1. Project Clover database Sat Apr 27 2024 12:01:29 CDT
  2. Package org.semanticweb.owlapi.rdf.rdfxml.parser

File TripleHandlers.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
37% of files have more coverage

Code metrics

348
1,055
369
94
3,144
2,442
584
0.55
2.86
3.93
1.58

Classes

Class Line # Actions
TripleHandlers 46 0 0% 1 1
0.00%
TripleHandlers.HandlerAccessor 52 186 0% 55 0
1.0100%
TripleHandlers.AbstractNamedEquivalentClassAxiomHandler 505 8 0% 4 0
1.0100%
TripleHandlers.AbstractResourceTripleHandler 533 13 0% 10 0
1.0100%
TripleHandlers.AbstractTripleHandler 574 86 0% 55 111
0.2626%
TripleHandlers.AbstractTripleHandler.ClassExpressionMatcher 826 1 0% 2 2
0.3333333433.3%
TripleHandlers.AbstractTripleHandler.DataRangeMatcher 836 1 0% 2 2
0.3333333433.3%
TripleHandlers.AbstractTripleHandler.IndividualMatcher 846 1 0% 2 2
0.3333333433.3%
TripleHandlers.AbstractBuiltInTypeHandler 857 5 0% 4 0
1.0100%
TripleHandlers.GTPAnnotationLiteralHandler 883 33 0% 15 10
0.830508583.1%
TripleHandlers.GTPAnnotationResourceTripleHandler 948 21 0% 8 2
0.9393939493.9%
TripleHandlers.GTPDataPropertyAssertionHandler 997 7 0% 5 0
1.0100%
TripleHandlers.GTPLiteralTripleHandler 1026 7 0% 7 17
0.00%
TripleHandlers.GTPObjectPropertyAssertionHandler 1053 8 0% 6 1
0.937593.8%
TripleHandlers.GTPResourceTripleHandler 1084 3 0% 4 7
0.00%
TripleHandlers.SKOSClassTripleHandler 1104 4 0% 2 6
0.00%
TripleHandlers.TPAllValuesFromHandler 1118 11 0% 8 0
1.0100%
TripleHandlers.TPAnnotatedPropertyHandler 1145 4 0% 3 0
1.0100%
TripleHandlers.TPAnnotatedSourceHandler 1162 4 0% 3 0
1.0100%
TripleHandlers.TPAnnotatedTargetHandler 1179 4 0% 3 1
0.8571428785.7%
TripleHandlers.TPComplementOfHandler 1196 5 0% 3 0
1.0100%
TripleHandlers.TPDatatypeComplementOfHandler 1215 5 0% 4 1
0.888888988.9%
TripleHandlers.TPDeclaredAsHandler 1238 10 0% 7 19
0.09523819.5%
TripleHandlers.TPDifferentFromHandler 1263 7 0% 3 0
1.0100%
TripleHandlers.TPDisjointUnionHandler 1284 9 0% 5 1
0.9333333493.3%
TripleHandlers.TPDisjointWithHandler 1314 10 0% 4 0
1.0100%
TripleHandlers.TPDistinctMembersHandler 1348 5 0% 3 0
1.0100%
TripleHandlers.TPEquivalentClassHandler 1368 24 0% 15 10
0.7575%
TripleHandlers.TPEquivalentPropertyHandler 1423 15 0% 7 0
1.0100%
TripleHandlers.TPFirstLiteralHandler 1455 5 0% 4 0
1.0100%
TripleHandlers.TPFirstResourceHandler 1478 4 0% 3 0
1.0100%
TripleHandlers.TPHasKeyHandler 1496 9 0% 4 1
0.928571492.9%
TripleHandlers.TPHasValueHandler 1522 3 0% 3 6
0.00%
TripleHandlers.TPImportsHandler 1538 24 0% 10 9
0.769230876.9%
TripleHandlers.TPIntersectionOfHandler 1594 11 0% 7 4
0.818181881.8%
TripleHandlers.TPInverseOfHandler 1621 10 0% 9 2
0.888888988.9%
TripleHandlers.TPOnClassHandler 1661 4 0% 4 3
0.62562.5%
TripleHandlers.TPOnDataRangeHandler 1682 4 0% 4 3
0.62562.5%
TripleHandlers.TPOnPropertyHandler 1703 3 0% 3 1
0.833333383.3%
TripleHandlers.TPOneOfHandler 1719 2 0% 2 0
1.0100%
TripleHandlers.TPPropertyChainAxiomHandler 1731 8 0% 3 0
1.0100%
TripleHandlers.TPPropertyDisjointWithHandler 1753 11 0% 8 0
1.0100%
TripleHandlers.TPPropertyDomainHandler 1787 18 0% 14 1
0.9687596.9%
TripleHandlers.TPPropertyRangeHandler 1834 43 0% 25 28
0.616438361.6%
TripleHandlers.TPRestHandler 1906 5 0% 4 0
1.0100%
TripleHandlers.TPSameAsHandler 1926 7 0% 3 0
1.0100%
TripleHandlers.TPSomeValuesFromHandler 1947 8 0% 5 0
1.0100%
TripleHandlers.TPSubClassOfHandler 1975 17 0% 11 6
0.7931034679.3%
TripleHandlers.TPSubPropertyOfHandler 2020 40 0% 23 8
0.8904109689%
TripleHandlers.TPTypeHandler 2097 11 0% 7 2
0.990%
TripleHandlers.TPUnionOfHandler 2130 2 0% 2 0
1.0100%
TripleHandlers.TPVersionIRIHandler 2142 12 0% 7 2
0.990%
TripleHandlers.AbstractTriplePredicateHandler 2180 5 0% 3 0
1.0100%
TripleHandlers.TypeAllDifferentHandler 2202 8 0% 5 3
0.7857142778.6%
TripleHandlers.TypeAllDisjointClassesHandler 2230 9 0% 5 3
0.880%
TripleHandlers.TypeAllDisjointPropertiesHandler 2259 11 0% 5 3
0.833333383.3%
TripleHandlers.TypeAnnotationHandler 2289 2 0% 2 0
1.0100%
TripleHandlers.TypeAnnotationPropertyHandler 2301 7 0% 3 1
0.9090909490.9%
TripleHandlers.TypeAsymmetricPropertyHandler 2319 6 0% 4 1
0.9090909490.9%
TripleHandlers.TypeAxiomHandler 2341 45 0% 24 17
0.7820512778.2%
TripleHandlers.TypeClassHandler 2491 6 0% 3 0
1.0100%
TripleHandlers.TypeDataPropertyHandler 2508 6 0% 3 1
0.990%
TripleHandlers.TypeDataRangeHandler 2525 3 0% 3 5
0.285714328.6%
TripleHandlers.TypeDatatypeHandler 2539 6 0% 3 0
1.0100%
TripleHandlers.TypeDeprecatedClassHandler 2556 4 0% 2 0
1.0100%
TripleHandlers.TypeDeprecatedPropertyHandler 2570 3 0% 2 0
1.0100%
TripleHandlers.TypeFunctionalPropertyHandler 2583 8 0% 5 0
1.0100%
TripleHandlers.TypeInverseFunctionalPropertyHandler 2608 7 0% 4 1
0.916666791.7%
TripleHandlers.TypeIrreflexivePropertyHandler 2630 6 0% 4 1
0.9090909490.9%
TripleHandlers.TypeListHandler 2652 2 0% 2 0
1.0100%
TripleHandlers.TypeNamedIndividualHandler 2664 6 0% 3 0
1.0100%
TripleHandlers.TypeNegativeDataPropertyAssertionHandler 2681 29 0% 12 45
0.042553194.3%
TripleHandlers.TypeNegativePropertyAssertionHandler 2742 35 0% 19 11
0.8070175680.7%
TripleHandlers.TypeObjectPropertyHandler 2822 6 0% 3 0
1.0100%
TripleHandlers.TypeOntologyHandler 2839 7 0% 5 1
0.923076992.3%
TripleHandlers.TypeOntologyPropertyHandler 2861 3 0% 2 0
1.0100%
TripleHandlers.TypePropertyHandler 2876 3 0% 2 0
1.0100%
TripleHandlers.TypeRDFSClassHandler 2890 5 0% 3 1
0.888888988.9%
TripleHandlers.TypeReflexivePropertyHandler 2907 6 0% 4 1
0.9090909490.9%
TripleHandlers.TypeRestrictionHandler 2929 4 0% 2 0
1.0100%
TripleHandlers.TypeSWRLAtomListHandler 2943 2 0% 2 0
1.0100%
TripleHandlers.TypeSWRLBuiltInAtomHandler 2955 3 0% 2 0
1.0100%
TripleHandlers.TypeSWRLBuiltInHandler 2968 2 0% 2 0
1.0100%
TripleHandlers.TypeSWRLClassAtomHandler 2981 3 0% 2 0
1.0100%
TripleHandlers.TypeSWRLDataRangeAtomHandler 2994 3 0% 2 0
1.0100%
TripleHandlers.TypeSWRLDataValuedPropertyAtomHandler 3007 3 0% 2 0
1.0100%
TripleHandlers.TypeSWRLDifferentIndividualsAtomHandler 3020 3 0% 2 0
1.0100%
TripleHandlers.TypeSWRLImpHandler 3033 4 0% 2 0
1.0100%
TripleHandlers.TypeSWRLIndividualPropertyAtomHandler 3047 3 0% 2 0
1.0100%
TripleHandlers.TypeSWRLSameIndividualAtomHandler 3060 3 0% 2 0
1.0100%
TripleHandlers.TypeSWRLVariableHandler 3073 3 0% 2 0
1.0100%
TripleHandlers.TypeSelfRestrictionHandler 3086 4 0% 2 4
0.3333333433.3%
TripleHandlers.TypeSymmetricPropertyHandler 3101 8 0% 5 1
0.9333333493.3%
TripleHandlers.TypeTransitivePropertyHandler 3126 5 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2170 tests. .

Source view

1    /* This file is part of the OWL API.
2    * The contents of this file are subject to the LGPL License, Version 3.0.
3    * Copyright 2014, The University of Manchester
4    *
5    * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6    * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
7    * You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
8    *
9    * Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0 in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above.
10    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
11    * http://www.apache.org/licenses/LICENSE-2.0
12    * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
13    package org.semanticweb.owlapi.rdf.rdfxml.parser;
14   
15    import static org.semanticweb.owlapi.model.OWLOntologyLoaderConfiguration.MissingOntologyHeaderStrategy.INCLUDE_GRAPH;
16    import static org.semanticweb.owlapi.util.OWLAPIPreconditions.verifyNotNull;
17    import static org.semanticweb.owlapi.vocab.OWLRDFVocabulary.*;
18   
19    import java.util.HashSet;
20    import java.util.List;
21    import java.util.Map;
22    import java.util.Set;
23    import java.util.concurrent.ConcurrentHashMap;
24   
25    import javax.annotation.Nonnull;
26    import javax.annotation.Nullable;
27   
28    import org.semanticweb.owlapi.formats.AbstractRDFPrefixDocumentFormat;
29    import org.semanticweb.owlapi.io.RDFTriple;
30    import org.semanticweb.owlapi.model.*;
31    import org.semanticweb.owlapi.util.CollectionFactory;
32    import org.semanticweb.owlapi.vocab.OWL2Datatype;
33    import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;
34    import org.semanticweb.owlapi.vocab.SKOSVocabulary;
35    import org.semanticweb.owlapi.vocab.SWRLVocabulary;
36    import org.slf4j.Logger;
37    import org.slf4j.LoggerFactory;
38   
39    import com.google.common.base.Optional;
40   
41    /**
42    * @author Matthew Horridge, The University Of Manchester, Bio-Health
43    * Informatics Group
44    * @since 2.0.0
45    */
 
46    public class TripleHandlers {
47   
48    static final Logger LOGGER = LoggerFactory.getLogger(TripleHandlers.class);
49   
 
50  0 toggle private TripleHandlers() {}
51   
 
52    static class HandlerAccessor {
53   
54    /** Handlers for built in types */
55    @Nonnull private final Map<IRI, BuiltInTypeHandler> builtInTypes;
56    /**
57    * Handler for triples that denote nodes which represent axioms. i.e.
58    * owl:AllDisjointClasses owl:AllDisjointProperties owl:AllDifferent
59    * owl:NegativePropertyAssertion owl:Axiom These need to be handled
60    * separately from other types, because the base triples for annotated
61    * axioms should be in the ontology before annotations on the annotated
62    * versions of these axioms are parsed.
63    */
64    @Nonnull protected final Map<IRI, BuiltInTypeHandler> axiomTypes;
65    /** Handlers for build in predicates */
66    @Nonnull protected final Map<IRI, TriplePredicateHandler> predicates;
67    /**
68    * Handlers for general literal triples (i.e. triples which have
69    * predicates that are not part of the built in OWL/RDFS/RDF vocabulary.
70    * Such triples either constitute annotationIRIs of relationships
71    * between an individual and a data literal (typed or untyped)
72    */
73    protected final List<LiteralTripleHandler> literals;
74    /**
75    * Handlers for general resource triples (i.e. triples which have
76    * predicates that are not part of the built in OWL/RDFS/RDF vocabulary.
77    * Such triples either constitute annotationIRIs or relationships
78    * between an individual and another individual.
79    */
80    protected final List<ResourceTripleHandler> resources;
81    /** The inverse of handler. */
82    @Nonnull protected final TPInverseOfHandler inverseOf;
83    /** The non built in type handler. */
84    @Nonnull private final TPTypeHandler nonBuiltInTypes;
85    @Nonnull protected final OWLRDFConsumer consumer;
86   
 
87  3105 toggle HandlerAccessor(@Nonnull OWLRDFConsumer r) {
88  3105 consumer = r;
89  3105 builtInTypes = getBasicTypeHandlers(r, r.getConfiguration());
90  3105 axiomTypes = getAxiomTypeHandlers(r);
91  3105 inverseOf = new TPInverseOfHandler(r);
92  3105 nonBuiltInTypes = new TPTypeHandler(r);
93  3105 predicates = getPredicateHandlers(r);
94  3105 literals = getLiteralTripleHandlers(r);
95    // General resource/object triples - i.e. triples which have a
96    // predicate
97    // that is not a built in IRI. Annotation properties get precedence
98    // over object properties, so that if we have the statement
99    // a:A a:foo a:B and a:foo
100    // is typed as both an annotation and data property then the
101    // statement will be translated as an annotation on a:A
102  3105 resources = getResourceTripleHandlers(r);
103    }
104   
 
105  5437 toggle void apply(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull OWLLiteral object) {
106  5437 if (OWLRDFConsumer.isGeneralPredicate(predicate)) {
107  3912 for (LiteralTripleHandler lhandler : literals) {
108  10160 if (lhandler.canHandle(subject, predicate, object)) {
109  2721 lhandler.handleTriple(subject, predicate, object);
110  2721 return;
111    }
112    }
113    }
114    }
115   
 
116  18449 toggle void apply(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
117  18449 if (OWLRDFConsumer.isGeneralPredicate(predicate)) {
118  2660 for (ResourceTripleHandler handler : resources) {
119  5077 if (handler.canHandle(subject, predicate, object)) {
120  2639 handler.handleTriple(subject, predicate, object);
121  2639 return;
122    }
123    }
124    }
125    }
126   
 
127  15746 toggle void applyAnnotations(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
128  15746 BuiltInTypeHandler builtInTypeHandler = axiomTypes.get(object);
129  15746 if (builtInTypeHandler != null && builtInTypeHandler.canHandle(subject, predicate, object)) {
130  1863 builtInTypeHandler.handleTriple(subject, predicate, object);
131    }
132    }
133   
 
134  2395 toggle public void consumeNonReservedPredicateTriples() {
135  2395 consumer.iterateResourceTriples(new ResourceTripleIterator() {
136   
 
137  18449 toggle @Override
138    public void handleResourceTriple(IRI subject, @Nonnull IRI predicate, IRI object) {
139  18449 apply(subject, predicate, object);
140    }
141    });
142  2395 consumer.iterateLiteralTriples(new LiteralTripleIterator() {
143   
 
144  5437 toggle @Override
145    public void handleLiteralTriple(IRI subject, @Nonnull IRI predicate, OWLLiteral object) {
146  5437 apply(subject, predicate, object);
147    }
148    });
149    }
150   
 
151  2395 toggle public void consumeAnnotatedAxioms() {
152  2395 consumer.iterateResourceTriples(new ResourceTripleIterator() {
153   
 
154  15746 toggle @Override
155    public void handleResourceTriple(IRI subject, IRI predicate, IRI object) {
156  15746 applyAnnotations(subject, predicate, object);
157    }
158    });
159    }
160   
161    /**
162    * Called when a resource triple has been parsed.
163    *
164    * @param subject
165    * The subject of the triple that has been parsed
166    * @param predicate
167    * The predicate of the triple that has been parsed
168    * @param object
169    * The object of the triple that has been parsed
170    */
 
171  131233 toggle public void handleStreaming(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
172  131233 boolean consumed = false;
173  131233 if (predicate.equals(RDF_TYPE.getIRI())) {
174  64663 BuiltInTypeHandler handler = builtInTypes.get(object);
175  64663 if (handler != null) {
176  60514 if (handler.canHandleStreaming(subject, predicate, object)) {
177  59972 handler.handleTriple(subject, predicate, object);
178  59971 consumed = true;
179    }
180  4149 } else if (axiomTypes.get(object) == null) {
181    // Not a built in type
182  2195 consumer.addOWLNamedIndividual(subject, false);
183  2195 if (nonBuiltInTypes.canHandleStreaming(subject, predicate, object)) {
184  1940 nonBuiltInTypes.handleTriple(subject, predicate, object);
185  1940 consumed = true;
186    }
187    } else {
188  1954 consumer.addAxiom(subject);
189    }
190    } else {
191  66570 ResourceTripleHandler handler = predicates.get(predicate);
192  66570 if (handler != null) {
193  59158 if (handler.canHandleStreaming(subject, predicate, object)) {
194  44419 handler.handleTriple(subject, predicate, object);
195  44418 consumed = true;
196    }
197    } else {
198  7412 for (ResourceTripleHandler resHandler : resources) {
199  14824 if (resHandler.canHandleStreaming(subject, predicate, object)) {
200  251 resHandler.handleTriple(subject, predicate, object);
201  251 consumed = true;
202  251 break;
203    }
204    }
205    }
206    }
207  131231 if (!consumed) {
208    // Not consumed, so add the triple
209  24651 consumer.addTriple(subject, predicate, object);
210    }
211    }
212   
 
213  15854 toggle public void handleStreaming(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull String literal, IRI datatype,
214    String lang) {
215    // Convert all literals to OWLConstants
216  15854 OWLLiteral con = consumer.getOWLLiteral(literal, datatype, lang);
217  15854 handleStreaming(subject, predicate, con);
218    }
219   
 
220  15854 toggle private void handleStreaming(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull OWLLiteral con) {
221  15854 for (LiteralTripleHandler handler : literals) {
222  47410 if (handler.canHandleStreaming(subject, predicate, con)) {
223  10349 handler.handleTriple(subject, predicate, con);
224  10349 return;
225    }
226    }
227  5505 consumer.addTriple(subject, predicate, con);
228    }
229   
230    /**
231    * Handles triples in a non-streaming mode. Type triples whose type is
232    * an axiom type, are NOT handled.
233    *
234    * @param subject
235    * The subject of the triple
236    * @param predicate
237    * The predicate of the triple
238    * @param object
239    * The object of the triple
240    */
 
241  8845 toggle protected void handle(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
242  8845 if (predicate.equals(OWLRDFVocabulary.RDF_TYPE.getIRI())) {
243  1373 BuiltInTypeHandler typeHandler = builtInTypes.get(object);
244  1373 if (typeHandler != null) {
245  1022 typeHandler.handleTriple(subject, predicate, object);
246  351 } else if (axiomTypes.get(object) == null) {
247    // C(a)
248  263 OWLIndividual ind = consumer.translateIndividual(subject);
249  263 OWLClassExpression ce = consumer.translatorAccessor.translateClassExpression(object);
250  263 consumer.addAxiom(consumer.getDataFactory().getOWLClassAssertionAxiom(ce, ind, consumer
251    .getPendingAnnotations()));
252    }
253    } else {
254  7472 TriplePredicateHandler handler = predicates.get(predicate);
255  7472 if (handler != null && handler.canHandle(subject, predicate, object)) {
256  6368 handler.handleTriple(subject, predicate, object);
257    } else {
258  1104 for (ResourceTripleHandler resHandler : resources) {
259  2171 if (resHandler.canHandle(subject, predicate, object)) {
260  37 resHandler.handleTriple(subject, predicate, object);
261  37 break;
262    }
263    }
264    }
265    }
266    }
267   
268    /**
269    * Handle.
270    *
271    * @param subject
272    * the subject
273    * @param predicate
274    * the predicate
275    * @param object
276    * the object
277    */
 
278  95 toggle protected void handle(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull OWLLiteral object) {
279  95 for (LiteralTripleHandler handler : literals) {
280  269 if (handler.canHandle(subject, predicate, object)) {
281  48 handler.handleTriple(subject, predicate, object);
282  48 break;
283    }
284    }
285    }
286   
287    /**
288    * We need to mop up all remaining triples. These triples will be in the
289    * triples by subject map. Other triples which reside in the triples by
290    * predicate (single valued) triple aren't "root" triples for axioms.
291    * First we translate all system triples and then go for triples whose
292    * predicates are not system/reserved vocabulary IRIs to translate these
293    * into ABox assertions or annotationIRIs
294    *
295    * @return any remaining triples
296    */
 
297  2395 toggle @Nonnull
298    public Set<RDFTriple> mopUp() {
299    // We need to mop up all remaining triples. These triples will be in
300    // the triples by subject map. Other triples which reside in the
301    // triples by predicate (single valued) triple aren't "root" triples
302    // for axioms. First we translate all system triples, starting with
303    // property ranges, then go for triples whose predicates are not
304    // system/reserved vocabulary IRIs to translate these into ABox
305    // assertions or annotationIRIs
306  2395 consumer.iterateResourceTriples(new ResourceTripleIterator() {
307   
 
308  20074 toggle @Override
309    public void handleResourceTriple(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
310  20074 TriplePredicateHandler propertyRangeHandler = predicates.get(RDFS_RANGE.getIRI());
311  20074 if (propertyRangeHandler.canHandle(subject, predicate, object)) {
312  1589 propertyRangeHandler.handleTriple(subject, predicate, object);
313    }
314    }
315    });
316    // Now handle non-reserved predicate triples
317  2395 consumeNonReservedPredicateTriples();
318    // Now axiom annotations
319  2395 consumeAnnotatedAxioms();
320  2395 consumer.iterateResourceTriples(new ResourceTripleIterator() {
321   
 
322  7675 toggle @Override
323    public void handleResourceTriple(@Nonnull IRI subject, @Nonnull IRI predicate, IRI object) {
324  7675 handle(subject, predicate, object);
325    }
326    });
327  2395 consumer.iterateLiteralTriples(new LiteralTripleIterator() {
328   
 
329  53 toggle @Override
330    public void handleLiteralTriple(IRI subject, IRI predicate, OWLLiteral object) {
331  53 handle(subject, predicate, object);
332    }
333    });
334    // Inverse property axioms
335  2395 inverseOf.setAxiomParsingMode(true);
336  2395 consumer.iterateResourceTriples(new ResourceTripleIterator() {
337   
 
338  695 toggle @Override
339    public void handleResourceTriple(IRI subject, @Nonnull IRI predicate, IRI object) {
340  695 if (inverseOf.canHandle(subject, predicate, object)) {
341  199 inverseOf.handleTriple(subject, predicate, object);
342    }
343    }
344    });
345  2395 return getRemainingTriples();
346    }
347   
 
348  2395 toggle @Nonnull
349    private Set<RDFTriple> getRemainingTriples() {
350  2395 final Set<RDFTriple> remainingTriples = new HashSet<>();
351  2395 consumer.iterateResourceTriples(new ResourceTripleIterator() {
352   
 
353  496 toggle @Override
354    public void handleResourceTriple(IRI subject, IRI predicate, IRI object) {
355  496 remainingTriples.add(new RDFTriple(subject, consumer.isAnonymousNode(subject), predicate, object,
356    consumer.isAnonymousNode(object)));
357    }
358    });
359  2395 consumer.iterateLiteralTriples(new LiteralTripleIterator() {
360   
 
361  47 toggle @Override
362    public void handleLiteralTriple(@Nonnull IRI subject, @Nonnull IRI predicate,
363    @Nonnull OWLLiteral object) {
364  47 remainingTriples.add(new RDFTriple(subject, consumer.isAnonymousNode(subject), predicate, object));
365    }
366    });
367  2395 return remainingTriples;
368    }
369   
 
370  3105 toggle @Nonnull
371    private static List<ResourceTripleHandler> getResourceTripleHandlers(@Nonnull OWLRDFConsumer r) {
372  3105 return CollectionFactory.list((ResourceTripleHandler) new GTPObjectPropertyAssertionHandler(r),
373    new GTPAnnotationResourceTripleHandler(r));
374    }
375   
 
376  3105 toggle @Nonnull
377    protected Map<IRI, TriplePredicateHandler> getPredicateHandlers(@Nonnull OWLRDFConsumer r) {
378  3105 Map<IRI, TriplePredicateHandler> predicateHandlers = new ConcurrentHashMap<>();
379  3105 add(predicateHandlers, new TPDifferentFromHandler(r));
380  3105 add(predicateHandlers, new TPDisjointUnionHandler(r));
381  3105 add(predicateHandlers, new TPDisjointWithHandler(r));
382  3105 add(predicateHandlers, new TPEquivalentClassHandler(r));
383  3105 add(predicateHandlers, new TPEquivalentPropertyHandler(r));
384  3105 add(predicateHandlers, new TPPropertyDomainHandler(r));
385  3105 add(predicateHandlers, new TPPropertyRangeHandler(r));
386  3105 add(predicateHandlers, new TPSameAsHandler(r));
387  3105 add(predicateHandlers, new TPSubClassOfHandler(r));
388  3105 add(predicateHandlers, new TPSubPropertyOfHandler(r));
389  3105 add(predicateHandlers, nonBuiltInTypes);
390  3105 add(predicateHandlers, new TPDistinctMembersHandler(r));
391  3105 add(predicateHandlers, new TPImportsHandler(r));
392  3105 add(predicateHandlers, new TPIntersectionOfHandler(r));
393  3105 add(predicateHandlers, new TPUnionOfHandler(r));
394  3105 add(predicateHandlers, new TPComplementOfHandler(r));
395  3105 add(predicateHandlers, new TPOneOfHandler(r));
396  3105 add(predicateHandlers, new TPSomeValuesFromHandler(r));
397  3105 add(predicateHandlers, new TPAllValuesFromHandler(r));
398  3105 add(predicateHandlers, new TPRestHandler(r));
399  3105 add(predicateHandlers, new TPFirstResourceHandler(r));
400  3105 add(predicateHandlers, new TPDeclaredAsHandler(r));
401  3105 add(predicateHandlers, new TPHasKeyHandler(r));
402  3105 add(predicateHandlers, new TPVersionIRIHandler(r));
403  3105 add(predicateHandlers, new TPPropertyChainAxiomHandler(r));
404  3105 add(predicateHandlers, new TPAnnotatedSourceHandler(r));
405  3105 add(predicateHandlers, new TPAnnotatedPropertyHandler(r));
406  3105 add(predicateHandlers, new TPAnnotatedTargetHandler(r));
407  3105 add(predicateHandlers, new TPPropertyDisjointWithHandler(r));
408  3105 add(predicateHandlers, inverseOf);
409  3105 add(predicateHandlers, new TPOnPropertyHandler(r));
410  3105 add(predicateHandlers, new TPOnClassHandler(r));
411  3105 add(predicateHandlers, new TPOnDataRangeHandler(r));
412  3105 add(predicateHandlers, new TPComplementOfHandler(r));
413  3105 add(predicateHandlers, new TPDatatypeComplementOfHandler(r));
414  3105 return predicateHandlers;
415    }
416   
 
417  3105 toggle @Nonnull
418    public static Map<IRI, BuiltInTypeHandler> getAxiomTypeHandlers(@Nonnull OWLRDFConsumer r) {
419  3105 Map<IRI, BuiltInTypeHandler> map = new ConcurrentHashMap<>();
420  3105 add(map, new TypeAxiomHandler(r));
421  3105 add(map, new TypeAllDifferentHandler(r));
422  3105 add(map, new TypeAllDisjointClassesHandler(r));
423  3105 add(map, new TypeAllDisjointPropertiesHandler(r));
424  3105 add(map, new TypeNegativePropertyAssertionHandler(r));
425  3105 return map;
426    }
427   
428    /**
429    * General literal triples - i.e. triples which have a predicate that is
430    * not a built in IRI. Annotation properties get precedence over data
431    * properties, so that if we have the statement<br>
432    * a:A a:foo a:B<br>
433    * and a:foo is typed as both an annotation and data property then the
434    * statement will be translated as an annotation on a:A
435    *
436    * @param r
437    * consumer
438    * @return handlers
439    */
 
440  3105 toggle @Nonnull
441    public static List<LiteralTripleHandler> getLiteralTripleHandlers(@Nonnull OWLRDFConsumer r) {
442  3105 return CollectionFactory.list((LiteralTripleHandler) new GTPDataPropertyAssertionHandler(r),
443    new TPFirstLiteralHandler(r), new GTPAnnotationLiteralHandler(r));
444    }
445   
 
446  127261 toggle private static void add(@Nonnull Map<IRI, BuiltInTypeHandler> m, @Nonnull BuiltInTypeHandler h) {
447  127261 m.put(h.getTypeIRI(), h);
448    }
449   
 
450  108675 toggle private static void add(@Nonnull Map<IRI, TriplePredicateHandler> map, @Nonnull TriplePredicateHandler h) {
451  108675 map.put(h.getPredicateIRI(), h);
452    }
453   
 
454  3105 toggle @Nonnull
455    public static Map<IRI, BuiltInTypeHandler> getBasicTypeHandlers(@Nonnull OWLRDFConsumer r,
456    @Nonnull OWLOntologyLoaderConfiguration config) {
457  3105 Map<IRI, BuiltInTypeHandler> map = new ConcurrentHashMap<>();
458  3105 add(map, new TypeOntologyPropertyHandler(r));
459  3105 add(map, new TypeAsymmetricPropertyHandler(r));
460  3105 add(map, new TypeClassHandler(r));
461  3105 add(map, new TypeObjectPropertyHandler(r));
462  3105 add(map, new TypeDataPropertyHandler(r));
463  3105 add(map, new TypeDatatypeHandler(r));
464  3105 add(map, new TypeFunctionalPropertyHandler(r));
465  3105 add(map, new TypeInverseFunctionalPropertyHandler(r));
466  3105 add(map, new TypeIrreflexivePropertyHandler(r));
467  3105 add(map, new TypeReflexivePropertyHandler(r));
468  3105 add(map, new TypeSymmetricPropertyHandler(r));
469  3105 add(map, new TypeTransitivePropertyHandler(r));
470  3105 add(map, new TypeRestrictionHandler(r));
471  3105 add(map, new TypeListHandler(r));
472  3105 add(map, new TypeAnnotationPropertyHandler(r));
473  3105 add(map, new TypeDeprecatedClassHandler(r));
474  3105 add(map, new TypeDeprecatedPropertyHandler(r));
475  3105 add(map, new TypeDataRangeHandler(r));
476  3105 add(map, new TypeOntologyHandler(r));
477  3105 add(map, new TypeNegativeDataPropertyAssertionHandler(r));
478  3105 add(map, new TypeRDFSClassHandler(r));
479  3105 add(map, new TypeSelfRestrictionHandler(r));
480  3105 add(map, new TypePropertyHandler(r));
481  3105 add(map, new TypeNamedIndividualHandler(r));
482  3105 add(map, new TypeAnnotationHandler(r));
483  3105 if (!config.isStrict()) {
484  3101 add(map, new TypeSWRLAtomListHandler(r));
485  3101 add(map, new TypeSWRLBuiltInAtomHandler(r));
486  3101 add(map, new TypeSWRLBuiltInHandler(r));
487  3101 add(map, new TypeSWRLClassAtomHandler(r));
488  3101 add(map, new TypeSWRLDataRangeAtomHandler(r));
489  3101 add(map, new TypeSWRLDataValuedPropertyAtomHandler(r));
490  3101 add(map, new TypeSWRLDifferentIndividualsAtomHandler(r));
491  3101 add(map, new TypeSWRLImpHandler(r));
492  3101 add(map, new TypeSWRLIndividualPropertyAtomHandler(r));
493  3101 add(map, new TypeSWRLSameIndividualAtomHandler(r));
494  3101 add(map, new TypeSWRLVariableHandler(r));
495    }
496  3105 return map;
497    }
498    }
499   
500    /**
501    * A base handler for equivalent class axioms where the axiom is stated in a
502    * direct way without an equivalent class triple. For example A
503    * intersectionOf (C or C)
504    */
 
505    abstract static class AbstractNamedEquivalentClassAxiomHandler extends AbstractTriplePredicateHandler {
506   
 
507  15525 toggle AbstractNamedEquivalentClassAxiomHandler(@Nonnull OWLRDFConsumer consumer, IRI predicateIRI) {
508  15525 super(consumer, predicateIRI);
509    }
510   
 
511  1584 toggle @Override
512    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
513  1584 return false;
514    }
515   
 
516  856 toggle @Override
517    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
518  856 return super.canHandle(subject, predicate, object) && !isAnonymous(subject);
519    }
520   
 
521  160 toggle @Override
522    public void handleTriple(IRI subject, IRI predicate, IRI object) {
523  160 consumeTriple(subject, predicate, object);
524  160 Set<OWLClassExpression> operands = new HashSet<>();
525  160 operands.add(translateClassExpression(subject));
526  160 operands.add(translateEquivalentClass(object));
527  160 addAxiom(df.getOWLEquivalentClassesAxiom(operands));
528    }
529   
530    protected abstract OWLClassExpression translateEquivalentClass(@Nonnull IRI mainNode);
531    }
532   
 
533    abstract static class AbstractResourceTripleHandler extends AbstractTripleHandler implements ResourceTripleHandler {
534   
 
535  242146 toggle protected AbstractResourceTripleHandler(@Nonnull OWLRDFConsumer consumer) {
536  242146 super(consumer);
537    }
538   
 
539  4585 toggle protected boolean isSubjectOrObjectAnonymous(@Nonnull IRI subject, @Nonnull IRI object) {
540  4585 return isAnonymous(subject) || isAnonymous(object);
541    }
542   
 
543  1370 toggle protected boolean isSubjectAndObjectMatchingClassExpressionOrMatchingDataRange(IRI subject, IRI object) {
544  1370 return isSubjectAndObjectClassExpression(subject, object) || isSubjectAndObjectDataRange(subject, object);
545    }
546   
 
547  187 toggle protected boolean isSubjectAndObjectDataRange(IRI subject, IRI object) {
548  187 return consumer.isDataRange(subject) && consumer.isDataRange(object);
549    }
550   
 
551  2303 toggle protected boolean isSubjectAndObjectClassExpression(IRI subject, IRI object) {
552  2303 return consumer.isClassExpression(subject) && consumer.isClassExpression(object);
553    }
554   
555    /**
556    * @param subject
557    * subject
558    * @param object
559    * object
560    */
 
561  32139 toggle protected void inferTypes(IRI subject, IRI object) {
562  32139 if (consumer.isClassExpression(object)) {
563  16835 consumer.addClassExpression(subject, false);
564  15304 } else if (consumer.isDataRange(object)) {
565  1558 consumer.addDataRange(subject, false);
566  13746 } else if (consumer.isClassExpression(subject)) {
567  1597 consumer.addClassExpression(object, false);
568  12149 } else if (consumer.isDataRange(subject)) {
569  342 consumer.addDataRange(object, false);
570    }
571    }
572    }
573   
 
574    static class AbstractTripleHandler {
575   
576    @Nonnull protected final OWLRDFConsumer consumer;
577    @Nonnull private final ClassExpressionMatcher classExpressionMatcher = new ClassExpressionMatcher();
578    @Nonnull private final DataRangeMatcher dataRangeMatcher = new DataRangeMatcher();
579    @Nonnull private final IndividualMatcher individualMatcher = new IndividualMatcher();
580    protected final OWLDataFactory df;
581   
 
582  251461 toggle protected AbstractTripleHandler(@Nonnull OWLRDFConsumer consumer) {
583  251461 this.consumer = consumer;
584  251461 df = consumer.getDataFactory();
585    }
586   
 
587  28826 toggle @Nonnull
588    protected Set<OWLAnnotation> getPendingAnnotations() {
589  28826 return consumer.getPendingAnnotations();
590    }
591   
 
592  89890 toggle protected void consumeTriple(IRI subject, IRI predicate, IRI object) {
593  89890 consumer.consumeTriple(subject, predicate, object);
594    }
595   
 
596  13118 toggle protected void consumeTriple(IRI subject, IRI predicate, OWLLiteral object) {
597  13118 consumer.consumeTriple(subject, predicate, object);
598    }
599   
 
600  31110 toggle protected boolean isStrict() {
601  31110 return consumer.getConfiguration().isStrict();
602    }
603   
 
604  0 toggle protected boolean isObjectPropertyOnly(IRI iri) {
605  0 return consumer.isObjectPropertyOnly(iri);
606    }
607   
 
608  0 toggle protected boolean isDataPropertyOnly(IRI iri) {
609  0 return consumer.isDataPropertyOnly(iri);
610    }
611   
 
612  1394 toggle protected boolean isAnnotationPropertyOnly(IRI iri) {
613  1394 return consumer.isAnnotationPropertyOnly(iri);
614    }
615   
 
616  0 toggle protected boolean isAnnotationPropertyStrict(IRI iri) {
617  0 return consumer.isAnnotationPropertyOnly(iri);
618    }
619   
 
620  0 toggle protected boolean isAnnotationPropertyLax(IRI iri) {
621  0 return consumer.isAnnotationProperty(iri);
622    }
623   
 
624  58801 toggle protected void addAxiom(@Nonnull OWLAxiom axiom) {
625  58801 consumer.addAxiom(axiom);
626    }
627   
 
628  14062 toggle @Nonnull
629    protected OWLClassExpression translateClassExpression(@Nonnull IRI iri) {
630  14062 return consumer.translatorAccessor.translateClassExpression(iri);
631    }
632   
 
633  6095 toggle @Nonnull
634    protected OWLObjectPropertyExpression translateObjectProperty(@Nonnull IRI iri) {
635  6095 return consumer.translateObjectPropertyExpression(iri);
636    }
637   
 
638  1531 toggle @Nonnull
639    protected OWLDataPropertyExpression translateDataProperty(@Nonnull IRI iri) {
640  1531 return consumer.translateDataPropertyExpression(iri);
641    }
642   
 
643  254 toggle @Nonnull
644    protected OWLDataRange translateDataRange(@Nonnull IRI iri) {
645  254 return consumer.translateDataRange(iri);
646    }
647   
 
648  3638 toggle @Nonnull
649    protected OWLIndividual translateIndividual(@Nonnull IRI iri) {
650  3638 return consumer.translateIndividual(iri);
651    }
652   
 
653  89885 toggle protected boolean isAnonymous(@Nonnull IRI node) {
654  89885 return consumer.isAnonymousNode(node);
655    }
656   
 
657  0 toggle protected boolean isResourcePresent(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
658  0 return consumer.getResourceObject(mainNode, predicate, false) != null;
659    }
660   
 
661  0 toggle protected boolean isLiteralPresent(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
662  0 return consumer.getLiteralObject(mainNode, predicate, false) != null;
663    }
664   
 
665  0 toggle protected boolean isRestrictionStrict(@Nonnull IRI node) {
666  0 return consumer.isRestriction(node);
667    }
668   
 
669  0 toggle protected boolean isRestrictionLax(@Nonnull IRI node) {
670  0 return consumer.isRestriction(node);
671    }
672   
 
673  0 toggle protected boolean isNonNegativeIntegerStrict(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
674  0 OWLLiteral literal = consumer.getLiteralObject(mainNode, predicate, false);
675  0 if (literal == null) {
676  0 return false;
677    }
678  0 OWLDatatype datatype = literal.getDatatype();
679  0 OWL2Datatype nni = OWL2Datatype.XSD_NON_NEGATIVE_INTEGER;
680  0 return datatype.getIRI().equals(nni.getIRI()) && nni.isInLexicalSpace(literal.getLiteral());
681    }
682   
 
683  0 toggle protected boolean isNonNegativeIntegerLax(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
684  0 OWLLiteral literal = consumer.getLiteralObject(mainNode, predicate, false);
685  0 if (literal == null) {
686  0 return false;
687    }
688  0 return OWL2Datatype.XSD_INTEGER.isInLexicalSpace(verifyNotNull(literal.getLiteral().trim()));
689    }
690   
 
691  0 toggle protected int translateInteger(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
692  0 OWLLiteral literal = consumer.getLiteralObject(mainNode, predicate, true);
693  0 if (literal == null) {
694  0 return 0;
695    }
696  0 try {
697  0 return Integer.parseInt(literal.getLiteral().trim());
698    } catch (NumberFormatException e) {
699  0 return 0;
700    }
701    }
702   
 
703  0 toggle protected boolean isClassExpressionStrict(@Nonnull IRI node) {
704  0 return consumer.isClassExpression(node) && !consumer.isDataRange(node);
705    }
706   
 
707  0 toggle protected boolean isClassExpressionStrict(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
708  0 IRI object = consumer.getResourceObject(mainNode, predicate, false);
709  0 return object != null && isClassExpressionStrict(object);
710    }
711   
 
712  10322 toggle protected boolean isClassExpressionLax(@Nonnull IRI mainNode) {
713  10322 return consumer.isClassExpression(mainNode) || consumer.isParsedAllTriples() && !consumer.isDataRange(
714    mainNode);
715    }
716   
 
717  0 toggle protected boolean isClassExpressionLax(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
718  0 IRI object = consumer.getResourceObject(mainNode, predicate, false);
719  0 return object != null && isClassExpressionLax(object);
720    }
721   
 
722  1609 toggle protected boolean isObjectPropertyStrict(@Nonnull IRI node) {
723  1609 return consumer.isObjectPropertyOnly(node);
724    }
725   
 
726  0 toggle protected boolean isObjectPropertyStrict(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
727  0 IRI object = consumer.getResourceObject(mainNode, predicate, false);
728  0 return object != null && isObjectPropertyStrict(object);
729    }
730   
 
731  3762 toggle protected boolean isObjectPropertyLax(@Nonnull IRI node) {
732  3762 return consumer.isObjectProperty(node);
733    }
734   
 
735  0 toggle protected boolean isObjectPropertyLax(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
736  0 IRI object = consumer.getResourceObject(mainNode, predicate, false);
737  0 return object != null && isObjectPropertyLax(object);
738    }
739   
 
740  1340 toggle protected boolean isDataPropertyStrict(@Nonnull IRI node) {
741  1340 return consumer.isDataPropertyOnly(node);
742    }
743   
 
744  0 toggle protected boolean isDataPropertyStrict(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
745  0 IRI object = consumer.getResourceObject(mainNode, predicate, false);
746  0 return object != null && isDataPropertyStrict(object);
747    }
748   
 
749  4004 toggle protected boolean isDataPropertyLax(@Nonnull IRI node) {
750  4004 return consumer.isDataProperty(node);
751    }
752   
 
753  0 toggle protected boolean isDataPropertyLax(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
754  0 IRI object = consumer.getResourceObject(mainNode, predicate, false);
755  0 return object != null && isDataPropertyLax(object);
756    }
757   
 
758  0 toggle protected boolean isDataRangeStrict(@Nonnull IRI node) {
759  0 return consumer.isDataRange(node) && !consumer.isClassExpression(node);
760    }
761   
 
762  0 toggle protected boolean isDataRangeStrict(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
763  0 IRI object = consumer.getResourceObject(mainNode, predicate, false);
764  0 assert object != null;
765  0 return isDataRangeStrict(object);
766    }
767   
 
768  234 toggle protected boolean isDataRangeLax(@Nonnull IRI node) {
769  234 return consumer.isDataRange(node);
770    }
771   
 
772  0 toggle protected boolean isDataRangeLax(@Nonnull IRI mainNode, @Nonnull OWLRDFVocabulary predicate) {
773  0 IRI object = consumer.getResourceObject(mainNode, predicate, false);
774  0 return object != null && isDataRangeLax(mainNode);
775    }
776   
 
777  0 toggle protected boolean isClassExpressionListStrict(@Nonnull IRI mainNode, int minSize) {
778  0 return isResourceListStrict(mainNode, classExpressionMatcher, minSize);
779    }
780   
 
781  0 toggle protected boolean isDataRangeListStrict(@Nonnull IRI mainNode, int minSize) {
782  0 return isResourceListStrict(mainNode, dataRangeMatcher, minSize);
783    }
784   
 
785  0 toggle protected boolean isIndividualListStrict(@Nonnull IRI mainNode, int minSize) {
786  0 return isResourceListStrict(mainNode, individualMatcher, minSize);
787    }
788   
 
789  0 toggle protected boolean isResourceListStrict(@Nullable IRI mainNode, @Nonnull TypeMatcher typeMatcher, int minSize) {
790  0 if (mainNode == null) {
791  0 return false;
792    }
793  0 IRI currentListNode = mainNode;
794  0 Set<IRI> visitedListNodes = new HashSet<>();
795  0 int size = 0;
796  0 while (true) {
797  0 IRI firstObject = consumer.getResourceObject(currentListNode, RDF_FIRST, false);
798  0 if (firstObject == null) {
799  0 return false;
800    }
801  0 if (!typeMatcher.isTypeStrict(firstObject)) {
802    // Something in the list that is not of the required type
803  0 return false;
804    } else {
805  0 size++;
806    }
807  0 IRI restObject = consumer.getResourceObject(currentListNode, RDF_REST, false);
808  0 if (visitedListNodes.contains(restObject)) {
809    // Cycle - Non-terminating
810  0 return false;
811    }
812  0 if (restObject == null) {
813    // Not terminated properly
814  0 return false;
815    }
816  0 if (restObject.equals(RDF_NIL.getIRI())) {
817    // Terminated properly
818  0 return size >= minSize;
819    }
820    // Carry on
821  0 visitedListNodes.add(restObject);
822  0 currentListNode = restObject;
823    }
824    }
825   
 
826    class ClassExpressionMatcher implements TypeMatcher {
827   
 
828  251461 toggle ClassExpressionMatcher() {}
829   
 
830  0 toggle @Override
831    public boolean isTypeStrict(@Nonnull IRI node) {
832  0 return isClassExpressionStrict(node);
833    }
834    }
835   
 
836    class DataRangeMatcher implements TypeMatcher {
837   
 
838  251461 toggle DataRangeMatcher() {}
839   
 
840  0 toggle @Override
841    public boolean isTypeStrict(@Nonnull IRI node) {
842  0 return isDataRangeStrict(node);
843    }
844    }
845   
 
846    class IndividualMatcher implements TypeMatcher {
847   
 
848  251461 toggle IndividualMatcher() {}
849   
 
850  0 toggle @Override
851    public boolean isTypeStrict(@Nonnull IRI node) {
852  0 return true;
853    }
854    }
855    }
856   
 
857    abstract static class AbstractBuiltInTypeHandler extends AbstractTriplePredicateHandler implements
858    BuiltInTypeHandler {
859   
860    private final IRI typeIRI;
861   
 
862  127261 toggle protected AbstractBuiltInTypeHandler(@Nonnull OWLRDFConsumer consumer, IRI typeIRI) {
863  127261 super(consumer, RDF_TYPE.getIRI());
864  127261 this.typeIRI = typeIRI;
865    }
866   
 
867  59570 toggle @Override
868    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
869  59570 return true;
870    }
871   
 
872  1951 toggle @Override
873    public boolean canHandle(IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
874  1951 return predicate.equals(RDF_TYPE.getIRI()) && object.equals(typeIRI);
875    }
876   
 
877  127261 toggle @Override
878    public IRI getTypeIRI() {
879  127261 return typeIRI;
880    }
881    }
882   
 
883    static class GTPAnnotationLiteralHandler extends AbstractTripleHandler implements LiteralTripleHandler {
884   
 
885  3105 toggle GTPAnnotationLiteralHandler(@Nonnull OWLRDFConsumer consumer) {
886  3105 super(consumer);
887    }
888   
 
889  15702 toggle @Override
890    public boolean canHandleStreaming(IRI subject, IRI predicate, OWLLiteral object) {
891  15702 return !isAnonymous(subject) && !consumer.isAnnotation(subject) && consumer.isAnnotationProperty(predicate);
892    }
893   
 
894  3211 toggle @Override
895    public boolean canHandle(IRI subject, IRI predicate, OWLLiteral object) {
896  3211 if (isStrict()) {
897  3 return isAnnotationPropertyOnly(predicate);
898    }
899  3208 boolean axiom = consumer.isAxiom(subject);
900  3208 if (axiom) {
901  1164 return false;
902    }
903  2044 boolean annotation = consumer.isAnnotation(subject);
904  2044 if (annotation) {
905  71 return false;
906    }
907  1973 if (consumer.isAnnotationProperty(predicate)) {
908  216 return true;
909    }
910  1757 if (!isAnonymous(subject)) {
911  1743 if (isClassExpressionLax(subject)) {
912  1736 return true;
913    }
914  7 if (isDataRangeLax(subject)) {
915  7 return true;
916    }
917  0 if (isObjectPropertyLax(subject)) {
918  0 return true;
919    }
920  0 if (isDataPropertyLax(subject)) {
921  0 return true;
922    }
923  0 return false;
924    }
925  14 return true;
926    }
927   
 
928  12170 toggle @Override
929    public void handleTriple(@Nonnull IRI subject, IRI predicate, OWLLiteral object) {
930  12170 OWLAnnotationProperty prop = df.getOWLAnnotationProperty(predicate);
931  12170 OWLAnnotationSubject annotationSubject;
932  12170 if (isAnonymous(subject)) {
933  32 annotationSubject = consumer.getOWLAnonymousIndividual(subject.toString());
934    } else {
935  12138 annotationSubject = subject;
936    }
937  12170 if (consumer.isOntology(subject)) {
938  55 consumer.addOntologyAnnotation(df.getOWLAnnotation(prop, object, getPendingAnnotations()));
939    } else {
940  12115 OWLAnnotationAssertionAxiom ax = df.getOWLAnnotationAssertionAxiom(prop, annotationSubject, object,
941    getPendingAnnotations());
942  12115 addAxiom(ax);
943    }
944  12170 consumeTriple(subject, predicate, object);
945    }
946    }
947   
 
948    static class GTPAnnotationResourceTripleHandler extends AbstractResourceTripleHandler {
949   
 
950  3105 toggle GTPAnnotationResourceTripleHandler(@Nonnull OWLRDFConsumer consumer) {
951  3105 super(consumer);
952    }
953   
 
954  7412 toggle @Override
955    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
956  7412 if (isStrict()) {
957  0 return false;
958    } else {
959  7412 return !isAnonymous(subject) && !isAnonymous(object) && consumer.isAnnotationProperty(predicate);
960    }
961    }
962   
 
963  3484 toggle @Override
964    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
965  3484 boolean builtInAnnotationProperty = BUILT_IN_ANNOTATION_PROPERTY_IRIS.contains(predicate);
966  3484 return !consumer.isAxiom(subject) && !consumer.isAnnotation(subject) && (builtInAnnotationProperty
967    || !predicate.isReservedVocabulary());
968    }
969   
 
970  2647 toggle @Override
971    public void handleTriple(@Nonnull IRI subject, IRI predicate, @Nonnull IRI object) {
972  2647 OWLAnnotationValue value;
973  2647 if (isAnonymous(object)) {
974  76 value = consumer.getOWLAnonymousIndividual(object.toString());
975    } else {
976  2571 value = object;
977    }
978  2647 OWLAnnotationProperty prop = df.getOWLAnnotationProperty(predicate);
979  2647 OWLAnnotation anno = df.getOWLAnnotation(prop, value);
980  2647 OWLAnnotationSubject annoSubject;
981  2647 if (isAnonymous(subject)) {
982  36 annoSubject = consumer.getOWLAnonymousIndividual(subject.toString());
983    } else {
984  2611 annoSubject = subject;
985    }
986  2647 if (consumer.isOntology(subject)) {
987    // Assume we annotation our ontology?
988  3 consumer.addOntologyAnnotation(anno);
989    } else {
990  2644 OWLAxiom decAx = df.getOWLAnnotationAssertionAxiom(annoSubject, anno, getPendingAnnotations());
991  2644 addAxiom(decAx);
992    }
993  2647 consumeTriple(subject, predicate, object);
994    }
995    }
996   
 
997    static class GTPDataPropertyAssertionHandler extends AbstractTripleHandler implements LiteralTripleHandler {
998   
 
999  3105 toggle GTPDataPropertyAssertionHandler(@Nonnull OWLRDFConsumer consumer) {
1000  3105 super(consumer);
1001    }
1002   
 
1003  4007 toggle @Override
1004    public boolean canHandle(IRI subject, IRI predicate, OWLLiteral object) {
1005  4007 if (isStrict()) {
1006  3 return isDataPropertyStrict(predicate);
1007    } else {
1008    // Handle annotation assertions as annotation assertions only!
1009  4004 return isDataPropertyLax(predicate) && !consumer.isAnnotationProperty(predicate);
1010    }
1011    }
1012   
 
1013  15854 toggle @Override
1014    public boolean canHandleStreaming(IRI subject, IRI predicate, OWLLiteral object) {
1015  15854 return false;
1016    }
1017   
 
1018  796 toggle @Override
1019    public void handleTriple(@Nonnull IRI subject, IRI predicate, OWLLiteral object) {
1020  796 addAxiom(df.getOWLDataPropertyAssertionAxiom(translateDataProperty(predicate), translateIndividual(subject),
1021    object, getPendingAnnotations()));
1022  796 consumeTriple(subject, predicate, object);
1023    }
1024    }
1025   
 
1026    static class GTPLiteralTripleHandler extends AbstractTripleHandler implements LiteralTripleHandler {
1027   
 
1028  0 toggle GTPLiteralTripleHandler(@Nonnull OWLRDFConsumer consumer) {
1029  0 super(consumer);
1030    }
1031   
 
1032  0 toggle @Override
1033    public void handleTriple(IRI subject, IRI predicate, OWLLiteral object) {
1034  0 if (isStrict()) {} else {
1035  0 if (isAnnotationPropertyLax(predicate)) {} else {}
1036    }
1037    }
1038   
 
1039  0 toggle @Override
1040    public boolean canHandleStreaming(IRI subject, IRI predicate, OWLLiteral object) {
1041  0 if (isStrict()) {
1042  0 return false;
1043    }
1044  0 return isAnnotationPropertyLax(predicate);
1045    }
1046   
 
1047  0 toggle @Override
1048    public boolean canHandle(IRI subject, IRI predicate, OWLLiteral object) {
1049  0 return isAnnotationPropertyStrict(predicate) || isDataPropertyStrict(predicate);
1050    }
1051    }
1052   
 
1053    static class GTPObjectPropertyAssertionHandler extends AbstractResourceTripleHandler {
1054   
 
1055  3105 toggle GTPObjectPropertyAssertionHandler(@Nonnull OWLRDFConsumer consumer) {
1056  3105 super(consumer);
1057    }
1058   
 
1059  3764 toggle @Override
1060    public boolean canHandle(IRI subject, IRI predicate, IRI object) {
1061  3764 if (isStrict()) {
1062  2 return isObjectPropertyStrict(predicate);
1063    } else {
1064    // Handle annotation assertions as annotation assertions only!
1065  3762 return isObjectPropertyLax(predicate) && !isAnnotationPropertyOnly(predicate);
1066    }
1067    }
1068   
 
1069  7412 toggle @Override
1070    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1071  7412 return false;
1072    }
1073   
 
1074  280 toggle @Override
1075    public void handleTriple(@Nonnull IRI subject, IRI predicate, @Nonnull IRI object) {
1076  280 if (consumer.isObjectProperty(predicate)) {
1077  280 consumeTriple(subject, predicate, object);
1078  280 addAxiom(df.getOWLObjectPropertyAssertionAxiom(translateObjectProperty(predicate), translateIndividual(
1079    subject), translateIndividual(object), getPendingAnnotations()));
1080    }
1081    }
1082    }
1083   
 
1084    static class GTPResourceTripleHandler extends AbstractResourceTripleHandler {
1085   
 
1086  0 toggle GTPResourceTripleHandler(@Nonnull OWLRDFConsumer consumer) {
1087  0 super(consumer);
1088    }
1089   
 
1090  0 toggle @Override
1091    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1092   
 
1093  0 toggle @Override
1094    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1095  0 return false;
1096    }
1097   
 
1098  0 toggle @Override
1099    public boolean canHandle(IRI subject, IRI predicate, IRI object) {
1100  0 return false;
1101    }
1102    }
1103   
 
1104    static class SKOSClassTripleHandler extends AbstractBuiltInTypeHandler {
1105   
 
1106  0 toggle SKOSClassTripleHandler(@Nonnull OWLRDFConsumer consumer, @Nonnull SKOSVocabulary v) {
1107  0 super(consumer, v.getIRI());
1108    }
1109   
 
1110  0 toggle @Override
1111    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1112  0 OWLIndividual ind = df.getOWLNamedIndividual(subject);
1113  0 OWLClass skosConcept = df.getOWLClass(object);
1114  0 addAxiom(df.getOWLClassAssertionAxiom(skosConcept, ind));
1115    }
1116    }
1117   
 
1118    static class TPAllValuesFromHandler extends AbstractTriplePredicateHandler {
1119   
 
1120  3105 toggle TPAllValuesFromHandler(@Nonnull OWLRDFConsumer consumer) {
1121  3105 super(consumer, OWL_ALL_VALUES_FROM.getIRI());
1122    }
1123   
 
1124  357 toggle @Override
1125    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1126  357 consumer.addOWLRestriction(subject, false);
1127  357 IRI propIRI = consumer.getResourceObject(subject, OWL_ON_PROPERTY.getIRI(), false);
1128  357 if (propIRI != null && (!consumer.isAnonymousNode(object) || consumer.translatorAccessor
1129    .getClassExpressionIfTranslated(object) != null)) {
1130    // The filler is either a datatype or named class
1131  220 if (consumer.isObjectPropertyOnly(propIRI)) {
1132  173 consumer.addClassExpression(object, false);
1133  173 consumer.addTriple(subject, predicate, object);
1134  173 consumer.translatorAccessor.translateClassExpression(subject);
1135  173 return true;
1136  47 } else if (consumer.isDataPropertyOnly(propIRI)) {}
1137    }
1138  184 return false;
1139    }
1140   
 
1141  173 toggle @Override
1142    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1143    }
1144   
 
1145    static class TPAnnotatedPropertyHandler extends AbstractTriplePredicateHandler {
1146   
 
1147  3105 toggle TPAnnotatedPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
1148  3105 super(consumer, OWL_ANNOTATED_PROPERTY.getIRI());
1149    }
1150   
 
1151  668 toggle @Override
1152    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1153  668 consumer.addAnnotatedSource(object, subject);
1154  668 consumer.checkForAndProcessAnnotatedDeclaration(subject);
1155  668 return false;
1156    }
1157   
 
1158  45 toggle @Override
1159    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1160    }
1161   
 
1162    static class TPAnnotatedSourceHandler extends AbstractTriplePredicateHandler {
1163   
 
1164  3105 toggle TPAnnotatedSourceHandler(@Nonnull OWLRDFConsumer consumer) {
1165  3105 super(consumer, OWL_ANNOTATED_SOURCE.getIRI());
1166    }
1167   
 
1168  668 toggle @Override
1169    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1170  668 consumer.addAnnotatedSource(object, subject);
1171  668 consumer.checkForAndProcessAnnotatedDeclaration(subject);
1172  668 return false;
1173    }
1174   
 
1175  45 toggle @Override
1176    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1177    }
1178   
 
1179    static class TPAnnotatedTargetHandler extends AbstractTriplePredicateHandler {
1180   
 
1181  3105 toggle TPAnnotatedTargetHandler(@Nonnull OWLRDFConsumer consumer) {
1182  3105 super(consumer, OWL_ANNOTATED_TARGET.getIRI());
1183    }
1184   
 
1185  581 toggle @Override
1186    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1187  581 consumer.addAnnotatedSource(object, subject);
1188  581 consumer.checkForAndProcessAnnotatedDeclaration(subject);
1189  581 return false;
1190    }
1191   
 
1192  0 toggle @Override
1193    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1194    }
1195   
 
1196    static class TPComplementOfHandler extends AbstractNamedEquivalentClassAxiomHandler {
1197   
 
1198  6210 toggle TPComplementOfHandler(@Nonnull OWLRDFConsumer consumer) {
1199  6210 super(consumer, OWL_COMPLEMENT_OF.getIRI());
1200    }
1201   
 
1202  235 toggle @Override
1203    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1204  235 consumer.addClassExpression(subject, false);
1205  235 consumer.addClassExpression(object, false);
1206  235 return super.canHandleStreaming(subject, predicate, object);
1207    }
1208   
 
1209  2 toggle @Override
1210    protected OWLClassExpression translateEquivalentClass(@Nonnull IRI mainNode) {
1211  2 return df.getOWLObjectComplementOf(consumer.translatorAccessor.translateClassExpression(mainNode));
1212    }
1213    }
1214   
 
1215    static class TPDatatypeComplementOfHandler extends AbstractTriplePredicateHandler {
1216   
 
1217  3105 toggle TPDatatypeComplementOfHandler(@Nonnull OWLRDFConsumer consumer) {
1218  3105 super(consumer, OWL_DATATYPE_COMPLEMENT_OF.getIRI());
1219    }
1220   
 
1221  47 toggle @Override
1222    public boolean canHandle(IRI subject, IRI predicate, IRI object) {
1223  47 return false;
1224    }
1225   
 
1226  0 toggle @Override
1227    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1228   
 
1229  71 toggle @Override
1230    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1231  71 consumer.addDataRange(subject, false);
1232  71 consumer.addDataRange(object, false);
1233  71 return false;
1234    }
1235    }
1236   
1237    @Deprecated
 
1238    static class TPDeclaredAsHandler extends AbstractTriplePredicateHandler {
1239   
 
1240  3105 toggle TPDeclaredAsHandler(@Nonnull OWLRDFConsumer consumer) {
1241  3105 super(consumer, DeprecatedVocabulary.OWL_DECLARED_AS);
1242    }
1243   
 
1244  0 toggle @Override
1245    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1246  0 return true;
1247    }
1248   
 
1249  0 toggle @Override
1250    public void handleTriple(IRI subject, IRI predicate, @Nonnull IRI object) {
1251  0 if (object.equals(OWL_CLASS.getIRI())) {
1252  0 addAxiom(df.getOWLDeclarationAxiom(df.getOWLClass(subject), getPendingAnnotations()));
1253  0 } else if (object.equals(OWL_OBJECT_PROPERTY.getIRI())) {
1254  0 addAxiom(df.getOWLDeclarationAxiom(df.getOWLObjectProperty(subject), getPendingAnnotations()));
1255  0 } else if (object.equals(OWL_DATA_PROPERTY.getIRI())) {
1256  0 addAxiom(df.getOWLDeclarationAxiom(df.getOWLDataProperty(subject), getPendingAnnotations()));
1257  0 } else if (object.equals(OWL_DATATYPE.getIRI())) {
1258  0 addAxiom(df.getOWLDeclarationAxiom(df.getOWLDatatype(subject), getPendingAnnotations()));
1259    }
1260    }
1261    }
1262   
 
1263    static class TPDifferentFromHandler extends AbstractTriplePredicateHandler {
1264   
 
1265  3105 toggle TPDifferentFromHandler(@Nonnull OWLRDFConsumer consumer) {
1266  3105 super(consumer, OWL_DIFFERENT_FROM.getIRI());
1267    }
1268   
 
1269  25 toggle @Override
1270    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1271  25 return true;
1272    }
1273   
 
1274  25 toggle @Override
1275    public void handleTriple(@Nonnull IRI subject, IRI predicate, @Nonnull IRI object) {
1276  25 Set<OWLIndividual> inds = new HashSet<>();
1277  25 inds.add(translateIndividual(subject));
1278  25 inds.add(translateIndividual(object));
1279  25 addAxiom(df.getOWLDifferentIndividualsAxiom(inds, getPendingAnnotations()));
1280  25 consumeTriple(subject, predicate, object);
1281    }
1282    }
1283   
 
1284    static class TPDisjointUnionHandler extends AbstractTriplePredicateHandler {
1285   
 
1286  3105 toggle TPDisjointUnionHandler(@Nonnull OWLRDFConsumer consumer) {
1287  3105 super(consumer, OWL_DISJOINT_UNION_OF.getIRI());
1288    }
1289   
 
1290  1 toggle @Override
1291    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
1292  1 return super.canHandle(subject, predicate, object) && !consumer.isAnonymousNode(subject) && consumer
1293    .isClassExpression(subject);
1294    }
1295   
 
1296  1 toggle @Override
1297    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1298  1 consumer.addClassExpression(subject, false);
1299  1 return false;
1300    }
1301   
 
1302  1 toggle @Override
1303    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1304  1 if (!consumer.isAnonymousNode(subject)) {
1305  1 OWLClass cls = (OWLClass) translateClassExpression(subject);
1306  1 Set<OWLClassExpression> classExpressions = consumer.translatorAccessor.translateToClassExpressionSet(
1307    object);
1308  1 addAxiom(df.getOWLDisjointUnionAxiom(cls, classExpressions, getPendingAnnotations()));
1309  1 consumeTriple(subject, predicate, object);
1310    }
1311    }
1312    }
1313   
 
1314    static class TPDisjointWithHandler extends AbstractTriplePredicateHandler {
1315   
 
1316  3105 toggle TPDisjointWithHandler(@Nonnull OWLRDFConsumer consumer) {
1317  3105 super(consumer, OWL_DISJOINT_WITH.getIRI());
1318    }
1319   
 
1320  922 toggle @Override
1321    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1322  922 consumer.addClassExpression(subject, false);
1323  922 consumer.addClassExpression(object, false);
1324    // NB: In strict parsing the above type triples won't get added
1325    // because
1326    // they aren't explicit,
1327    // so we need an extra check to see if there are type triples for
1328    // the
1329    // classes
1330  922 return !isSubjectOrObjectAnonymous(subject, object) && isSubjectAndObjectClassExpression(subject, object);
1331    }
1332   
 
1333  14 toggle @Override
1334    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
1335  14 return super.canHandle(subject, predicate, object) && isSubjectAndObjectClassExpression(subject, object);
1336    }
1337   
 
1338  933 toggle @Override
1339    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1340  933 Set<OWLClassExpression> operands = new HashSet<>();
1341  933 operands.add(translateClassExpression(subject));
1342  933 operands.add(translateClassExpression(object));
1343  933 addAxiom(df.getOWLDisjointClassesAxiom(operands, getPendingAnnotations()));
1344  933 consumeTriple(subject, predicate, object);
1345    }
1346    }
1347   
 
1348    static class TPDistinctMembersHandler extends AbstractTriplePredicateHandler {
1349   
 
1350  3105 toggle TPDistinctMembersHandler(@Nonnull OWLRDFConsumer consumer) {
1351  3105 super(consumer, OWL_DISTINCT_MEMBERS.getIRI());
1352    }
1353   
 
1354  88 toggle @Override
1355    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1356    // We need all of the list triples to be loaded :(
1357  88 return false;
1358    }
1359   
 
1360  88 toggle @Override
1361    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1362  88 Set<OWLIndividual> inds = consumer.translatorAccessor.translateToIndividualSet(object);
1363  88 addAxiom(df.getOWLDifferentIndividualsAxiom(inds, getPendingAnnotations()));
1364  88 consumeTriple(subject, predicate, object);
1365    }
1366    }
1367   
 
1368    static class TPEquivalentClassHandler extends AbstractTriplePredicateHandler {
1369   
 
1370  3105 toggle TPEquivalentClassHandler(@Nonnull OWLRDFConsumer consumer) {
1371  3105 super(consumer, OWL_EQUIVALENT_CLASS.getIRI());
1372    }
1373   
 
1374  1247 toggle @Override
1375    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
1376  1247 inferTypes(subject, object);
1377  1247 return super.canHandle(subject, predicate, object)
1378    && isSubjectAndObjectMatchingClassExpressionOrMatchingDataRange(subject, object);
1379    }
1380   
 
1381  1267 toggle @Override
1382    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1383  1267 inferTypes(subject, object);
1384  1267 return !isStrict() && !isSubjectOrObjectAnonymous(subject, object)
1385    && isSubjectAndObjectMatchingClassExpressionOrMatchingDataRange(subject, object);
1386    }
1387   
 
1388  1369 toggle @Override
1389    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1390  1369 if (isStrict()) {
1391  0 if (isClassExpressionStrict(subject) && isClassExpressionStrict(object)) {
1392  0 translateEquivalentClasses(subject, predicate, object);
1393  0 } else if (isDataRangeStrict(subject) && isDataRangeStrict(object)) {
1394  0 translateEquivalentDataRanges(subject, predicate, object);
1395    }
1396    } else {
1397  1369 if (isClassExpressionLax(subject) && isClassExpressionLax(object)) {
1398  1183 translateEquivalentClasses(subject, predicate, object);
1399  186 } else if (isDataRangeLax(subject) || isDataRangeLax(object)) {
1400  186 translateEquivalentDataRanges(subject, predicate, object);
1401    }
1402    }
1403    }
1404   
 
1405  186 toggle private void translateEquivalentDataRanges(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
1406  186 OWLDatatype datatype = df.getOWLDatatype(subject);
1407  186 OWLDataRange dataRange = consumer.translateDataRange(object);
1408  186 OWLDatatypeDefinitionAxiom def = df.getOWLDatatypeDefinitionAxiom(datatype, dataRange,
1409    getPendingAnnotations());
1410  186 addAxiom(def);
1411  186 consumeTriple(subject, predicate, object);
1412    }
1413   
 
1414  1183 toggle private void translateEquivalentClasses(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
1415  1183 Set<OWLClassExpression> operands = new HashSet<>();
1416  1183 operands.add(translateClassExpression(subject));
1417  1183 operands.add(translateClassExpression(object));
1418  1183 addAxiom(df.getOWLEquivalentClassesAxiom(operands, getPendingAnnotations()));
1419  1183 consumeTriple(subject, predicate, object);
1420    }
1421    }
1422   
 
1423    static class TPEquivalentPropertyHandler extends AbstractTriplePredicateHandler {
1424   
 
1425  3105 toggle TPEquivalentPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
1426  3105 super(consumer, OWL_EQUIVALENT_PROPERTY.getIRI());
1427    }
1428   
 
1429  162 toggle @Override
1430    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1431  162 return false;
1432    }
1433   
 
1434  224 toggle @Override
1435    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1436  224 Set<OWLAnnotation> pendingAnnotations = getPendingAnnotations();
1437  224 if (consumer.isObjectProperty(subject) && consumer.isObjectProperty(object)) {
1438  113 Set<OWLObjectPropertyExpression> props = new HashSet<>();
1439  113 props.add(translateObjectProperty(subject));
1440  113 props.add(translateObjectProperty(object));
1441  113 addAxiom(df.getOWLEquivalentObjectPropertiesAxiom(props, pendingAnnotations));
1442  113 consumeTriple(subject, predicate, object);
1443    }
1444  224 if (consumer.isDataProperty(subject) && consumer.isDataProperty(object)) {
1445  80 Set<OWLDataPropertyExpression> props = new HashSet<>();
1446  80 props.add(translateDataProperty(subject));
1447  80 props.add(translateDataProperty(object));
1448  80 addAxiom(df.getOWLEquivalentDataPropertiesAxiom(props, pendingAnnotations));
1449  80 consumeTriple(subject, predicate, object);
1450    }
1451    // TODO: LOG ERROR
1452    }
1453    }
1454   
 
1455    static class TPFirstLiteralHandler extends AbstractTripleHandler implements LiteralTripleHandler {
1456   
 
1457  3105 toggle TPFirstLiteralHandler(@Nonnull OWLRDFConsumer consumer) {
1458  3105 super(consumer);
1459    }
1460   
 
1461  3211 toggle @Override
1462    public boolean canHandle(IRI subject, @Nullable IRI predicate, OWLLiteral object) {
1463  3211 return predicate != null && predicate.equals(RDF_FIRST.getIRI());
1464    }
1465   
 
1466  15854 toggle @Override
1467    public boolean canHandleStreaming(IRI subject, @Nullable IRI predicate, OWLLiteral object) {
1468  15854 return predicate != null && predicate.equals(RDF_FIRST.getIRI());
1469    }
1470   
 
1471  152 toggle @Override
1472    public void handleTriple(IRI subject, IRI predicate, OWLLiteral object) {
1473  152 consumer.addFirst(subject, object);
1474  152 consumeTriple(subject, predicate, object);
1475    }
1476    }
1477   
 
1478    static class TPFirstResourceHandler extends AbstractTriplePredicateHandler {
1479   
 
1480  3105 toggle TPFirstResourceHandler(@Nonnull OWLRDFConsumer consumer) {
1481  3105 super(consumer, RDF_FIRST.getIRI());
1482    }
1483   
 
1484  20852 toggle @Override
1485    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1486  20852 return true;
1487    }
1488   
 
1489  20852 toggle @Override
1490    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1491  20852 consumer.addFirst(subject, object);
1492  20852 consumeTriple(subject, predicate, object);
1493    }
1494    }
1495   
 
1496    static class TPHasKeyHandler extends AbstractTriplePredicateHandler {
1497   
1498    private final OptimisedListTranslator<OWLPropertyExpression> listTranslator;
1499   
 
1500  3105 toggle TPHasKeyHandler(@Nonnull OWLRDFConsumer consumer) {
1501  3105 super(consumer, OWL_HAS_KEY.getIRI());
1502  3105 listTranslator = Translators.getListTranslator(consumer);
1503    }
1504   
 
1505  75 toggle @Override
1506    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1507  75 consumer.addClassExpression(subject, false);
1508  75 return false;
1509    }
1510   
 
1511  78 toggle @Override
1512    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1513  78 if (consumer.isClassExpression(subject)) {
1514  78 consumeTriple(subject, predicate, object);
1515  78 OWLClassExpression ce = translateClassExpression(subject);
1516  78 Set<OWLPropertyExpression> props = listTranslator.translateToSet(object);
1517  78 addAxiom(df.getOWLHasKeyAxiom(ce, props, getPendingAnnotations()));
1518    }
1519    }
1520    }
1521   
 
1522    static class TPHasValueHandler extends AbstractTriplePredicateHandler {
1523   
 
1524  0 toggle TPHasValueHandler(@Nonnull OWLRDFConsumer consumer) {
1525  0 super(consumer, OWL_HAS_VALUE.getIRI());
1526    }
1527   
 
1528  0 toggle @Override
1529    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1530   
 
1531  0 toggle @Override
1532    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1533  0 consumer.addOWLRestriction(subject, false);
1534  0 return false;
1535    }
1536    }
1537   
 
1538    static class TPImportsHandler extends AbstractTriplePredicateHandler {
1539   
 
1540  3105 toggle TPImportsHandler(@Nonnull OWLRDFConsumer consumer) {
1541  3105 super(consumer, OWL_IMPORTS.getIRI());
1542    }
1543   
 
1544  34 toggle @Override
1545    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1546  34 return true;
1547    }
1548   
 
1549  34 toggle @Override
1550    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1551  34 consumeTriple(subject, predicate, object);
1552  34 consumer.addOntology(subject);
1553  34 consumer.addOntology(object);
1554  34 OWLImportsDeclaration importsDeclaration = df.getOWLImportsDeclaration(object);
1555  34 consumer.addImport(importsDeclaration);
1556  34 if (!consumer.getConfiguration().isIgnoredImport(object)) {
1557  34 OWLOntologyManager man = consumer.getOWLOntologyManager();
1558  34 man.makeLoadImportRequest(importsDeclaration, consumer.getConfiguration());
1559  33 OWLOntology importedOntology = man.getImportedOntology(importsDeclaration);
1560  33 if (importedOntology != null) {
1561  33 OWLDocumentFormat importedOntologyFormat = man.getOntologyFormat(importedOntology);
1562  33 if (importedOntologyFormat instanceof AbstractRDFPrefixDocumentFormat && importedOntology
1563    .isAnonymous()) {
1564  3 if (consumer.getConfiguration().getMissingOntologyHeaderStrategy() == INCLUDE_GRAPH) {
1565    // We should have just included the triples rather
1566    // than imported them. So,
1567    // we remove the imports statement, add the axioms
1568    // from the imported ontology to
1569    // out importing ontology and remove the imported
1570    // ontology.
1571    // WHO EVER THOUGHT THAT THIS WAS A GOOD IDEA?
1572  3 man.applyChange(new RemoveImport(consumer.getOntology(), importsDeclaration));
1573  3 for (OWLImportsDeclaration decl : importedOntology.getImportsDeclarations()) {
1574  0 assert decl != null;
1575  0 man.applyChange(new AddImport(consumer.getOntology(), decl));
1576    }
1577  3 for (OWLAnnotation anno : importedOntology.getAnnotations()) {
1578  0 assert anno != null;
1579  0 man.applyChange(new AddOntologyAnnotation(consumer.getOntology(), anno));
1580    }
1581  3 for (OWLAxiom ax : importedOntology.getAxioms()) {
1582  45 consumer.addAxiom(ax);
1583    }
1584  3 man.removeOntology(importedOntology);
1585    }
1586    }
1587    }
1588  33 consumer.importsClosureChanged();
1589    }
1590    }
1591    }
1592   
1593    /** A handler for top level intersection classes. */
 
1594    static class TPIntersectionOfHandler extends AbstractNamedEquivalentClassAxiomHandler {
1595   
 
1596  3105 toggle TPIntersectionOfHandler(@Nonnull OWLRDFConsumer consumer) {
1597  3105 super(consumer, OWL_INTERSECTION_OF.getIRI());
1598    }
1599   
 
1600  141 toggle @Override
1601    protected OWLClassExpression translateEquivalentClass(IRI mainNode) {
1602  141 return df.getOWLObjectIntersectionOf(consumer.translatorAccessor.translateToClassExpressionSet(mainNode));
1603    }
1604   
 
1605  855 toggle @Override
1606    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1607  855 if (consumer.isClassExpression(subject)) {
1608  739 consumer.addClassExpression(object, false);
1609  116 } else if (consumer.isClassExpression(object)) {
1610  0 consumer.addClassExpression(subject, false);
1611  116 } else if (consumer.isDataRange(subject)) {
1612  63 consumer.addDataRange(object, false);
1613  53 } else if (consumer.isDataRange(object)) {
1614  0 consumer.addDataRange(subject, false);
1615    }
1616  855 return super.canHandleStreaming(subject, predicate, object);
1617    }
1618    }
1619   
1620    /** owl:inverseOf is used in both property expressions AND axioms. */
 
1621    static class TPInverseOfHandler extends AbstractTriplePredicateHandler {
1622   
1623    private boolean axiomParsingMode = false;
1624   
 
1625  3105 toggle TPInverseOfHandler(@Nonnull OWLRDFConsumer consumer) {
1626  3105 super(consumer, OWL_INVERSE_OF.getIRI());
1627    }
1628   
 
1629  0 toggle public boolean isAxiomParsingMode() {
1630  0 return axiomParsingMode;
1631    }
1632   
 
1633  2395 toggle public void setAxiomParsingMode(boolean axiomParsingMode) {
1634  2395 this.axiomParsingMode = axiomParsingMode;
1635    }
1636   
 
1637  472 toggle @Override
1638    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1639  472 consumer.addObjectProperty(subject, false);
1640  472 consumer.addObjectProperty(object, false);
1641  472 return false;
1642    }
1643   
 
1644  1082 toggle @Override
1645    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
1646  1082 return super.canHandle(subject, predicate, object) && consumer.isObjectProperty(subject) && consumer
1647    .isObjectProperty(object);
1648    }
1649   
 
1650  582 toggle @Override
1651    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1652    // Only do axiom translation
1653  582 if (axiomParsingMode && consumer.isObjectProperty(subject) && consumer.isObjectProperty(object)) {
1654  199 addAxiom(df.getOWLInverseObjectPropertiesAxiom(translateObjectProperty(subject),
1655    translateObjectProperty(object), getPendingAnnotations()));
1656  199 consumeTriple(subject, predicate, object);
1657    }
1658    }
1659    }
1660   
 
1661    static class TPOnClassHandler extends AbstractTriplePredicateHandler {
1662   
 
1663  3105 toggle TPOnClassHandler(@Nonnull OWLRDFConsumer consumer) {
1664  3105 super(consumer, OWL_ON_CLASS.getIRI());
1665    }
1666   
 
1667  0 toggle @Override
1668    public boolean canHandle(IRI subject, IRI predicate, IRI object) {
1669  0 return false;
1670    }
1671   
 
1672  0 toggle @Override
1673    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1674   
 
1675  182 toggle @Override
1676    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1677  182 consumer.addClassExpression(object, false);
1678  182 return false;
1679    }
1680    }
1681   
 
1682    static class TPOnDataRangeHandler extends AbstractTriplePredicateHandler {
1683   
 
1684  3105 toggle TPOnDataRangeHandler(@Nonnull OWLRDFConsumer consumer) {
1685  3105 super(consumer, OWL_ON_DATA_RANGE.getIRI());
1686    }
1687   
 
1688  0 toggle @Override
1689    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1690   
 
1691  0 toggle @Override
1692    public boolean canHandle(IRI subject, IRI predicate, IRI object) {
1693  0 return false;
1694    }
1695   
 
1696  24 toggle @Override
1697    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1698  24 consumer.addDataRange(object, true);
1699  24 return false;
1700    }
1701    }
1702   
 
1703    static class TPOnPropertyHandler extends AbstractTriplePredicateHandler {
1704   
 
1705  3105 toggle TPOnPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
1706  3105 super(consumer, OWL_ON_PROPERTY.getIRI());
1707    }
1708   
 
1709  2444 toggle @Override
1710    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1711  2444 consumer.addOWLRestriction(subject, false);
1712  2444 return false;
1713    }
1714   
 
1715  0 toggle @Override
1716    public void handleTriple(IRI subject, IRI predicate, IRI object) {}
1717    }
1718   
 
1719    static class TPOneOfHandler extends AbstractNamedEquivalentClassAxiomHandler {
1720   
 
1721  3105 toggle TPOneOfHandler(@Nonnull OWLRDFConsumer consumer) {
1722  3105 super(consumer, OWL_ONE_OF.getIRI());
1723    }
1724   
 
1725  12 toggle @Override
1726    protected OWLClassExpression translateEquivalentClass(IRI mainNode) {
1727  12 return df.getOWLObjectOneOf(consumer.translatorAccessor.translateToIndividualSet(mainNode));
1728    }
1729    }
1730   
 
1731    static class TPPropertyChainAxiomHandler extends AbstractTriplePredicateHandler {
1732   
 
1733  3105 toggle TPPropertyChainAxiomHandler(@Nonnull OWLRDFConsumer consumer) {
1734  3105 super(consumer, OWL_PROPERTY_CHAIN_AXIOM.getIRI());
1735    }
1736   
 
1737  169 toggle @Override
1738    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1739  169 consumer.addObjectProperty(object, false);
1740  169 return false;
1741    }
1742   
 
1743  179 toggle @Override
1744    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1745  179 OWLObjectPropertyExpression superProp = consumer.translateObjectPropertyExpression(subject);
1746  179 List<OWLObjectPropertyExpression> chain = consumer.translatorAccessor.translateToObjectPropertyList(object);
1747  179 consumeTriple(subject, predicate, object);
1748  179 Set<OWLAnnotation> annos = getPendingAnnotations();
1749  179 addAxiom(df.getOWLSubPropertyChainOfAxiom(chain, superProp, annos));
1750    }
1751    }
1752   
 
1753    static class TPPropertyDisjointWithHandler extends AbstractTriplePredicateHandler {
1754   
 
1755  3105 toggle TPPropertyDisjointWithHandler(@Nonnull OWLRDFConsumer consumer) {
1756  3105 super(consumer, OWL_PROPERTY_DISJOINT_WITH.getIRI());
1757    }
1758   
 
1759  113 toggle @Override
1760    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
1761  113 inferTypes(subject, object);
1762  113 return super.canHandle(subject, predicate, object) && (consumer.isObjectProperty(subject) && consumer
1763    .isObjectProperty(object) || consumer.isDataProperty(subject) && consumer.isDataProperty(object));
1764    }
1765   
 
1766  97 toggle @Override
1767    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1768  97 if (consumer.isDataProperty(subject) && consumer.isDataProperty(object)) {
1769  20 addAxiom(df.getOWLDisjointDataPropertiesAxiom(CollectionFactory.createSet(translateDataProperty(
1770    subject), translateDataProperty(object)), getPendingAnnotations()));
1771  20 consumeTriple(subject, predicate, object);
1772    }
1773  97 if (consumer.isObjectProperty(subject) && consumer.isObjectProperty(object)) {
1774  77 addAxiom(df.getOWLDisjointObjectPropertiesAxiom(CollectionFactory.createSet(translateObjectProperty(
1775    subject), translateObjectProperty(object)), getPendingAnnotations()));
1776  77 consumeTriple(subject, predicate, object);
1777    }
1778    }
1779   
 
1780  107 toggle @Override
1781    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1782  107 inferTypes(subject, object);
1783  107 return false;
1784    }
1785    }
1786   
 
1787    static class TPPropertyDomainHandler extends AbstractTriplePredicateHandler {
1788   
 
1789  3105 toggle TPPropertyDomainHandler(@Nonnull OWLRDFConsumer consumer) {
1790  3105 super(consumer, RDFS_DOMAIN.getIRI());
1791    }
1792   
 
1793  1417 toggle @Override
1794    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1795  1417 return false;
1796    }
1797   
 
1798  1417 toggle @Override
1799    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1800  1417 if (consumer.isObjectProperty(subject) && consumer.isClassExpression(object)) {
1801  1276 translateObjectPropertyDomain(subject, predicate, object);
1802  141 } else if (consumer.isDataPropertyOnly(subject) && consumer.isClassExpression(object)) {
1803  119 translateDataPropertyDomain(subject, predicate, object);
1804  22 } else if (consumer.isAnnotationProperty(subject) && consumer.isClassExpression(object) && !consumer
1805    .isAnonymousNode(object)) {
1806  4 translateAnnotationPropertyDomain(subject, predicate, object);
1807  18 } else if (!isStrict()) {
1808  18 consumer.addAnnotationProperty(subject, false);
1809  18 translateAnnotationPropertyDomain(subject, predicate, object);
1810    }
1811    }
1812   
 
1813  22 toggle private void translateAnnotationPropertyDomain(@Nonnull IRI subject, @Nonnull IRI predicate,
1814    @Nonnull IRI object) {
1815  22 OWLAnnotationProperty prop = df.getOWLAnnotationProperty(subject);
1816  22 addAxiom(df.getOWLAnnotationPropertyDomainAxiom(prop, object, getPendingAnnotations()));
1817    // TODO: Handle anonymous domain - error?
1818  22 consumeTriple(subject, predicate, object);
1819    }
1820   
 
1821  119 toggle private void translateDataPropertyDomain(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
1822  119 addAxiom(df.getOWLDataPropertyDomainAxiom(translateDataProperty(subject), translateClassExpression(object),
1823    getPendingAnnotations()));
1824  119 consumeTriple(subject, predicate, object);
1825    }
1826   
 
1827  1276 toggle private void translateObjectPropertyDomain(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
1828  1276 addAxiom(df.getOWLObjectPropertyDomainAxiom(translateObjectProperty(subject), translateClassExpression(
1829    object), getPendingAnnotations()));
1830  1276 consumeTriple(subject, predicate, object);
1831    }
1832    }
1833   
 
1834    static class TPPropertyRangeHandler extends AbstractTriplePredicateHandler {
1835   
 
1836  3105 toggle TPPropertyRangeHandler(@Nonnull OWLRDFConsumer consumer) {
1837  3105 super(consumer, RDFS_RANGE.getIRI());
1838    }
1839   
 
1840  1589 toggle @Override
1841    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1842  1589 inferTypes(subject, object);
1843  1589 return false;
1844    }
1845   
 
1846  1607 toggle @Override
1847    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1848  1607 if (isStrict()) {
1849  0 if (isObjectPropertyStrict(subject) && isClassExpressionStrict(object)) {
1850  0 translateAsObjectPropertyRange(subject, predicate, object);
1851  0 } else if (isDataPropertyStrict(subject) && isDataRangeStrict(object)) {
1852  0 translateAsDataPropertyRange(subject, predicate, object);
1853  0 } else if (consumer.isAnnotationProperty(subject) && !consumer.isAnonymousNode(object)) {
1854  0 translateAsAnnotationPropertyRange(subject, predicate, object);
1855    }
1856    } else {
1857  1607 if (isObjectPropertyStrict(subject) && consumer.isClassExpression(object)) {
1858  270 translateAsObjectPropertyRange(subject, predicate, object);
1859  1337 } else if (isDataPropertyStrict(subject) && consumer.isDataRange(object)) {
1860  213 translateAsDataPropertyRange(subject, predicate, object);
1861  1124 } else if (consumer.isAnnotationProperty(subject) && !consumer.isAnonymousNode(object)) {
1862  13 translateAsAnnotationPropertyRange(subject, predicate, object);
1863  1111 } else if (isAnnotationPropertyOnly(subject) && !isAnonymous(object)) {
1864  0 translateAsAnnotationPropertyRange(subject, predicate, object);
1865  1111 } else if (isClassExpressionLax(object)) {
1866  1070 consumer.addObjectProperty(subject, false);
1867  1070 translateAsObjectPropertyRange(subject, predicate, object);
1868  41 } else if (isDataRangeLax(object)) {
1869  41 consumer.addDataProperty(subject, false);
1870  41 translateAsDataPropertyRange(subject, predicate, object);
1871  0 } else if (isObjectPropertyLax(subject)) {
1872  0 consumer.addObjectProperty(subject, false);
1873  0 translateAsObjectPropertyRange(subject, predicate, object);
1874  0 } else if (isDataPropertyLax(subject)) {
1875  0 consumer.addDataProperty(subject, false);
1876  0 translateAsDataPropertyRange(subject, predicate, object);
1877    } else {
1878  0 consumer.addAnnotationProperty(subject, false);
1879  0 translateAsAnnotationPropertyRange(subject, predicate, object);
1880    }
1881    }
1882    }
1883   
 
1884  13 toggle private void translateAsAnnotationPropertyRange(@Nonnull IRI subject, @Nonnull IRI predicate,
1885    @Nonnull IRI object) {
1886  13 OWLAnnotationProperty prop = df.getOWLAnnotationProperty(subject);
1887  13 addAxiom(df.getOWLAnnotationPropertyRangeAxiom(prop, object, getPendingAnnotations()));
1888  13 consumeTriple(subject, predicate, object);
1889    }
1890   
 
1891  254 toggle private void translateAsDataPropertyRange(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
1892  254 OWLDataPropertyExpression property = translateDataProperty(subject);
1893  254 OWLDataRange dataRange = translateDataRange(object);
1894  254 addAxiom(df.getOWLDataPropertyRangeAxiom(property, dataRange, getPendingAnnotations()));
1895  254 consumeTriple(subject, predicate, object);
1896    }
1897   
 
1898  1340 toggle private void translateAsObjectPropertyRange(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
1899  1340 OWLObjectPropertyExpression property = translateObjectProperty(subject);
1900  1340 OWLClassExpression range = translateClassExpression(object);
1901  1340 addAxiom(df.getOWLObjectPropertyRangeAxiom(property, range, getPendingAnnotations()));
1902  1340 consumeTriple(subject, predicate, object);
1903    }
1904    }
1905   
 
1906    static class TPRestHandler extends AbstractTriplePredicateHandler {
1907   
 
1908  3105 toggle TPRestHandler(@Nonnull OWLRDFConsumer consumer) {
1909  3105 super(consumer, RDF_REST.getIRI());
1910    }
1911   
 
1912  21004 toggle @Override
1913    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1914  21004 return true;
1915    }
1916   
 
1917  21004 toggle @Override
1918    public void handleTriple(IRI subject, IRI predicate, @Nonnull IRI object) {
1919  21004 if (!object.equals(RDF_NIL.getIRI())) {
1920  19040 consumer.addRest(subject, object);
1921    }
1922  21004 consumeTriple(subject, predicate, object);
1923    }
1924    }
1925   
 
1926    static class TPSameAsHandler extends AbstractTriplePredicateHandler {
1927   
 
1928  3105 toggle TPSameAsHandler(@Nonnull OWLRDFConsumer consumer) {
1929  3105 super(consumer, OWL_SAME_AS.getIRI());
1930    }
1931   
 
1932  146 toggle @Override
1933    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1934  146 return true;
1935    }
1936   
 
1937  146 toggle @Override
1938    public void handleTriple(@Nonnull IRI subject, IRI predicate, @Nonnull IRI object) {
1939  146 Set<OWLIndividual> inds = new HashSet<>();
1940  146 inds.add(translateIndividual(subject));
1941  146 inds.add(translateIndividual(object));
1942  146 addAxiom(df.getOWLSameIndividualAxiom(inds, consumer.getPendingAnnotations()));
1943  146 consumeTriple(subject, predicate, object);
1944    }
1945    }
1946   
 
1947    static class TPSomeValuesFromHandler extends AbstractTriplePredicateHandler {
1948   
 
1949  3105 toggle TPSomeValuesFromHandler(@Nonnull OWLRDFConsumer consumer) {
1950  3105 super(consumer, OWL_SOME_VALUES_FROM.getIRI());
1951    }
1952   
 
1953  793 toggle @Override
1954    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1955  793 handleTriple(subject, predicate, object);
1956  793 return false;
1957    }
1958   
 
1959  793 toggle @Override
1960    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1961  793 consumer.addOWLRestriction(subject, false);
1962  793 if (consumer.isDataRange(object)) {
1963  46 IRI property = consumer.getResourceObject(subject, OWL_ON_PROPERTY.getIRI(), false);
1964  46 if (property != null) {
1965  34 consumer.addDataProperty(property, false);
1966    }
1967    }
1968    }
1969    }
1970   
1971    /**
1972    * Handles rdfs:subClassOf triples. If handling is set to strict then the
1973    * triple is only consumed if the subject and object are typed as classes.
1974    */
 
1975    static class TPSubClassOfHandler extends AbstractTriplePredicateHandler {
1976   
 
1977  3105 toggle TPSubClassOfHandler(@Nonnull OWLRDFConsumer consumer) {
1978  3105 super(consumer, RDFS_SUBCLASS_OF.getIRI());
1979    }
1980   
 
1981  1316 toggle @Override
1982    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
1983  1316 return super.canHandle(subject, predicate, object) && isTyped(subject, object);
1984    }
1985   
 
1986  1316 toggle private boolean isTyped(IRI subject, IRI object) {
1987  1316 return consumer.isClassExpression(subject) && consumer.isClassExpression(object);
1988    }
1989   
 
1990  2398 toggle @Override
1991    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
1992  2398 consumer.addClassExpression(subject, false);
1993  2398 consumer.addClassExpression(object, false);
1994  2398 return !isStrict() && !isSubjectOrObjectAnonymous(subject, object);
1995    }
1996   
 
1997  2458 toggle @Override
1998    public void handleTriple(IRI subject, IRI predicate, IRI object) {
1999  2458 if (isStrict()) {
2000  0 if (isClassExpressionStrict(subject) && isClassExpressionStrict(object)) {
2001  0 translate(subject, predicate, object);
2002    }
2003    } else {
2004  2458 if (isClassExpressionLax(subject) && isClassExpressionLax(object)) {
2005  2458 translate(subject, predicate, object);
2006    }
2007    }
2008    }
2009   
 
2010  2458 toggle private void translate(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
2011  2458 OWLClassExpression subClass = translateClassExpression(subject);
2012  2458 OWLClassExpression supClass = translateClassExpression(object);
2013  2458 Set<OWLAnnotation> pendingAnnotations = consumer.getPendingAnnotations();
2014  2458 OWLAxiom ax = df.getOWLSubClassOfAxiom(subClass, supClass, pendingAnnotations);
2015  2458 addAxiom(ax);
2016  2458 consumeTriple(subject, predicate, object);
2017    }
2018    }
2019   
 
2020    static class TPSubPropertyOfHandler extends AbstractTriplePredicateHandler {
2021   
 
2022  3105 toggle TPSubPropertyOfHandler(@Nonnull OWLRDFConsumer consumer) {
2023  3105 super(consumer, RDFS_SUB_PROPERTY_OF.getIRI());
2024    }
2025   
 
2026  1019 toggle @Override
2027    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2028  1019 if (consumer.isObjectProperty(object)) {
2029  229 consumer.addObjectProperty(subject, false);
2030  790 } else if (consumer.isDataProperty(object)) {
2031  1 consumer.addDataProperty(object, false);
2032  789 } else if (consumer.isAnnotationProperty(object)) {
2033  31 consumer.addAnnotationProperty(subject, false);
2034  758 } else if (consumer.isObjectProperty(subject)) {
2035  54 consumer.addObjectProperty(object, false);
2036  704 } else if (consumer.isDataProperty(subject)) {
2037  16 consumer.addDataProperty(object, false);
2038  688 } else if (consumer.isAnnotationProperty(subject)) {
2039  2 consumer.addAnnotationProperty(object, false);
2040    }
2041  1019 return false;
2042    }
2043   
 
2044  1019 toggle @Override
2045    public void handleTriple(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
2046    // First check for object property chain
2047  1019 if (!isStrict() && consumer.hasPredicate(subject, DeprecatedVocabulary.OWL_PROPERTY_CHAIN)) {
2048    // Property chain
2049  12 IRI chainList = consumer.getResourceObject(subject, DeprecatedVocabulary.OWL_PROPERTY_CHAIN, true);
2050  12 assert chainList != null;
2051  12 List<OWLObjectPropertyExpression> properties = consumer.translatorAccessor
2052    .translateToObjectPropertyList(chainList);
2053  12 addAxiom(df.getOWLSubPropertyChainOfAxiom(properties, translateObjectProperty(object),
2054    getPendingAnnotations()));
2055  12 consumeTriple(subject, predicate, object);
2056  1007 } else if (!isStrict() && consumer.hasPredicate(subject, RDF_FIRST.getIRI())) {
2057    // Legacy object property chain representation
2058  0 List<OWLObjectPropertyExpression> properties = consumer.translatorAccessor
2059    .translateToObjectPropertyList(subject);
2060  0 addAxiom(df.getOWLSubPropertyChainOfAxiom(properties, translateObjectProperty(object),
2061    getPendingAnnotations()));
2062  0 consumeTriple(subject, predicate, object);
2063  1007 } else if (consumer.isObjectProperty(subject) && consumer.isObjectProperty(object)) {
2064  865 translateSubObjectProperty(subject, predicate, object);
2065  142 } else if (consumer.isDataProperty(subject) && consumer.isDataProperty(object)) {
2066  35 translateSubDataProperty(subject, predicate, object);
2067  107 } else if (!isStrict()) {
2068  107 if (consumer.isObjectProperty(object)) {
2069  2 translateSubObjectProperty(subject, predicate, object);
2070  105 } else if (consumer.isDataProperty(object)) {
2071  0 translateSubDataProperty(subject, predicate, object);
2072    } else {
2073  105 OWLAnnotationProperty subAnnoProp = df.getOWLAnnotationProperty(subject);
2074  105 OWLAnnotationProperty superAnnoProp = df.getOWLAnnotationProperty(object);
2075  105 addAxiom(df.getOWLSubAnnotationPropertyOfAxiom(subAnnoProp, superAnnoProp,
2076    getPendingAnnotations()));
2077    }
2078  107 consumeTriple(subject, predicate, object);
2079    }
2080    }
2081   
 
2082  867 toggle private void translateSubObjectProperty(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
2083    // Object - object
2084  867 addAxiom(df.getOWLSubObjectPropertyOfAxiom(translateObjectProperty(subject), translateObjectProperty(
2085    object), getPendingAnnotations()));
2086  867 consumeTriple(subject, predicate, object);
2087    }
2088   
 
2089  35 toggle private void translateSubDataProperty(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
2090    // Data - Data
2091  35 addAxiom(df.getOWLSubDataPropertyOfAxiom(translateDataProperty(subject), translateDataProperty(object),
2092    getPendingAnnotations()));
2093  35 consumeTriple(subject, predicate, object);
2094    }
2095    }
2096   
 
2097    static class TPTypeHandler extends AbstractTriplePredicateHandler {
2098   
 
2099  3105 toggle TPTypeHandler(@Nonnull OWLRDFConsumer consumer) {
2100  3105 super(consumer, RDF_TYPE.getIRI());
2101    }
2102   
 
2103  2195 toggle @Override
2104    public boolean canHandleStreaming(IRI subject, IRI predicate, @Nonnull IRI object) {
2105    // Can handle if object isn;t anonymous and either the object
2106    // IRI is owl:Thing, or it is not part of the build in vocabulary
2107  2195 consumer.addClassExpression(object, false);
2108  2195 if (isAnonymous(object)) {
2109  231 return false;
2110    }
2111  1964 if (object.isReservedVocabulary()) {
2112  124 return object.equals(OWL_THING.getIRI());
2113    }
2114  1840 return true;
2115    }
2116   
 
2117  1940 toggle @Override
2118    public void handleTriple(@Nonnull IRI subject, IRI predicate, @Nonnull IRI object) {
2119  1940 if (BUILT_IN_VOCABULARY_IRIS.contains(object) && !object.equals(OWL_THING.getIRI())) {
2120    // Can't have instance of built in vocabulary!
2121    // Shall we throw an exception here?
2122  0 LOGGER.info("Individual of builtin type {}", object);
2123    }
2124  1940 addAxiom(df.getOWLClassAssertionAxiom(translateClassExpression(object), translateIndividual(subject),
2125    getPendingAnnotations()));
2126  1940 consumeTriple(subject, predicate, object);
2127    }
2128    }
2129   
 
2130    static class TPUnionOfHandler extends AbstractNamedEquivalentClassAxiomHandler {
2131   
 
2132  3105 toggle TPUnionOfHandler(@Nonnull OWLRDFConsumer consumer) {
2133  3105 super(consumer, OWL_UNION_OF.getIRI());
2134    }
2135   
 
2136  5 toggle @Override
2137    protected OWLClassExpression translateEquivalentClass(IRI mainNode) {
2138  5 return df.getOWLObjectUnionOf(consumer.translatorAccessor.translateToClassExpressionSet(mainNode));
2139    }
2140    }
2141   
 
2142    static class TPVersionIRIHandler extends AbstractTriplePredicateHandler {
2143   
 
2144  3105 toggle TPVersionIRIHandler(@Nonnull OWLRDFConsumer consumer) {
2145  3105 super(consumer, OWL_VERSION_IRI.getIRI());
2146    }
2147   
 
2148  39 toggle @Override
2149    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2150  39 OWLOntology ontology = consumer.getOntology();
2151    // only setup the versionIRI if it is null before this point
2152  39 if (!ontology.getOntologyID().getVersionIRI().isPresent()) {
2153  15 Optional<IRI> ontologyIRI = ontology.getOntologyID().getOntologyIRI();
2154  15 Optional<IRI> versionIRI = Optional.of(object);
2155    // If there was no ontologyIRI before this point and the subject
2156    // of this statement was not anonymous,
2157    // then use the subject IRI as the ontology IRI, else we keep
2158    // the previous definition for the ontology IRI
2159  15 if (!ontologyIRI.isPresent() && !isAnonymous(subject)) {
2160  0 ontologyIRI = Optional.of(subject);
2161    }
2162  15 OWLOntologyID ontologyID = new OWLOntologyID(ontologyIRI, versionIRI);
2163  15 consumer.setOntologyID(ontologyID);
2164    }
2165  39 consumeTriple(subject, predicate, object);
2166    }
2167   
 
2168  39 toggle @Override
2169    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2170    // Always apply at the end
2171  39 return false;
2172    }
2173   
 
2174  39 toggle @Override
2175    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
2176  39 return predicate.equals(OWL_VERSION_IRI.getIRI());
2177    }
2178    }
2179   
 
2180    abstract static class AbstractTriplePredicateHandler extends AbstractResourceTripleHandler implements
2181    TriplePredicateHandler {
2182   
2183    private final IRI predicateIRI;
2184   
 
2185  235936 toggle AbstractTriplePredicateHandler(@Nonnull OWLRDFConsumer consumer, IRI predicateIRI) {
2186  235936 super(consumer);
2187  235936 this.predicateIRI = predicateIRI;
2188    }
2189   
 
2190  27816 toggle @Override
2191    public boolean canHandle(IRI subject, @Nonnull IRI predicate, IRI object) {
2192  27816 inferTypes(subject, object);
2193  27816 return predicate.equals(predicateIRI);
2194    }
2195   
 
2196  108675 toggle @Override
2197    public IRI getPredicateIRI() {
2198  108675 return predicateIRI;
2199    }
2200    }
2201   
 
2202    static class TypeAllDifferentHandler extends AbstractBuiltInTypeHandler {
2203   
 
2204  3105 toggle TypeAllDifferentHandler(@Nonnull OWLRDFConsumer consumer) {
2205  3105 super(consumer, OWL_ALL_DIFFERENT.getIRI());
2206    }
2207   
 
2208  90 toggle @Override
2209    public boolean canHandle(IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
2210  90 return super.canHandle(subject, predicate, object) && consumer.getResourceObject(subject, OWL_MEMBERS,
2211    false) != null;
2212    }
2213   
 
2214  2 toggle @Override
2215    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2216  2 IRI listNode = consumer.getResourceObject(subject, OWL_MEMBERS.getIRI(), true);
2217  2 if (listNode != null) {
2218  2 Set<OWLIndividual> inds = consumer.translatorAccessor.translateToIndividualSet(listNode);
2219  2 addAxiom(df.getOWLDifferentIndividualsAxiom(inds, getPendingAnnotations()));
2220  2 consumeTriple(subject, predicate, object);
2221    }
2222    }
2223   
 
2224  0 toggle @Override
2225    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2226  0 return false;
2227    }
2228    }
2229   
 
2230    static class TypeAllDisjointClassesHandler extends AbstractBuiltInTypeHandler {
2231   
 
2232  3105 toggle TypeAllDisjointClassesHandler(@Nonnull OWLRDFConsumer consumer) {
2233  3105 super(consumer, OWL_ALL_DISJOINT_CLASSES.getIRI());
2234    }
2235   
 
2236  92 toggle @Override
2237    public boolean canHandle(IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
2238  92 return super.canHandle(subject, predicate, object) && consumer.getResourceObject(subject, OWL_MEMBERS,
2239    false) != null;
2240    }
2241   
 
2242  92 toggle @Override
2243    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2244  92 IRI listNode = consumer.getResourceObject(subject, OWL_MEMBERS.getIRI(), true);
2245  92 if (listNode != null) {
2246  92 Set<OWLClassExpression> desc = consumer.translatorAccessor.translateToClassExpressionSet(listNode);
2247  92 Set<OWLAnnotation> annotations = consumer.translateAnnotations(subject);
2248  92 addAxiom(df.getOWLDisjointClassesAxiom(desc, annotations));
2249  92 consumeTriple(subject, predicate, object);
2250    }
2251    }
2252   
 
2253  0 toggle @Override
2254    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2255  0 return false;
2256    }
2257    }
2258   
 
2259    static class TypeAllDisjointPropertiesHandler extends AbstractBuiltInTypeHandler {
2260   
 
2261  3105 toggle TypeAllDisjointPropertiesHandler(@Nonnull OWLRDFConsumer consumer) {
2262  3105 super(consumer, OWL_ALL_DISJOINT_PROPERTIES.getIRI());
2263    }
2264   
 
2265  35 toggle @Override
2266    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2267  35 consumeTriple(subject, predicate, object);
2268  35 IRI listNode = consumer.getResourceObject(subject, OWL_MEMBERS.getIRI(), true);
2269  35 assert listNode != null;
2270  35 if (consumer.isObjectProperty(consumer.getFirstResource(listNode, false))) {
2271  17 Set<OWLAnnotation> annotations = consumer.translateAnnotations(subject);
2272  17 List<OWLObjectPropertyExpression> props = consumer.translatorAccessor.translateToObjectPropertyList(
2273    listNode);
2274  17 consumer.addAxiom(df.getOWLDisjointObjectPropertiesAxiom(new HashSet<>(props), annotations));
2275    } else {
2276  18 Set<OWLAnnotation> annotations = consumer.translateAnnotations(subject);
2277  18 List<OWLDataPropertyExpression> props = consumer.translatorAccessor.translateToDataPropertyList(
2278    listNode);
2279  18 consumer.addAxiom(df.getOWLDisjointDataPropertiesAxiom(new HashSet<>(props), annotations));
2280    }
2281    }
2282   
 
2283  0 toggle @Override
2284    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2285  0 return false;
2286    }
2287    }
2288   
 
2289    static class TypeAnnotationHandler extends AbstractBuiltInTypeHandler {
2290   
 
2291  3105 toggle TypeAnnotationHandler(@Nonnull OWLRDFConsumer consumer) {
2292  3105 super(consumer, OWL_ANNOTATION.getIRI());
2293    }
2294   
 
2295  45 toggle @Override
2296    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2297  45 consumer.addAnnotationIRI(subject);
2298    }
2299    }
2300   
 
2301    static class TypeAnnotationPropertyHandler extends AbstractBuiltInTypeHandler {
2302   
 
2303  3105 toggle TypeAnnotationPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2304  3105 super(consumer, OWL_ANNOTATION_PROPERTY.getIRI());
2305    }
2306   
 
2307  1041 toggle @Override
2308    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2309  1041 if (!isAnonymous(subject)) {
2310  1041 Set<OWLAnnotation> annos = consumer.getPendingAnnotations();
2311  1041 OWLAnnotationProperty property = df.getOWLAnnotationProperty(subject);
2312  1041 addAxiom(df.getOWLDeclarationAxiom(property, annos));
2313  1041 consumeTriple(subject, predicate, object);
2314    }
2315  1041 consumer.addAnnotationProperty(subject, true);
2316    }
2317    }
2318   
 
2319    static class TypeAsymmetricPropertyHandler extends AbstractBuiltInTypeHandler {
2320   
 
2321  3105 toggle TypeAsymmetricPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2322  3105 super(consumer, OWL_ASYMMETRIC_PROPERTY.getIRI());
2323    }
2324   
 
2325  74 toggle @Override
2326    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2327  74 consumer.addObjectProperty(subject, false);
2328  74 return !isAnonymous(subject);
2329    }
2330   
 
2331  82 toggle @Override
2332    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2333  82 if (consumer.isObjectProperty(subject)) {
2334  82 addAxiom(df.getOWLAsymmetricObjectPropertyAxiom(translateObjectProperty(subject),
2335    getPendingAnnotations()));
2336  82 consumeTriple(subject, predicate, object);
2337    }
2338    }
2339    }
2340   
 
2341    static class TypeAxiomHandler extends AbstractBuiltInTypeHandler {
2342   
 
2343  3105 toggle TypeAxiomHandler(@Nonnull OWLRDFConsumer consumer) {
2344  3105 this(consumer, OWL_AXIOM.getIRI());
2345    }
2346   
 
2347  3105 toggle TypeAxiomHandler(@Nonnull OWLRDFConsumer consumer, IRI typeIRI) {
2348  3105 super(consumer, typeIRI);
2349    }
2350   
 
2351  0 toggle @Override
2352    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2353    // We can't handle this is a streaming fashion, because we can't
2354    // be sure that the subject, predicate, object triples have been
2355    // parsed.
2356  0 consumer.addAxiom(subject);
2357  0 return false;
2358    }
2359   
2360    /**
2361    * Gets the IRI of the predicate of the triple that specifies the target
2362    * of a reified axiom
2363    *
2364    * @return The IRI, by default this is owl:annotatedTarget
2365    */
 
2366  662 toggle protected static OWLRDFVocabulary getTargetTriplePredicate() {
2367  662 return OWL_ANNOTATED_TARGET;
2368    }
2369   
2370    /**
2371    * Gets the IRI of the predicate of the triple that specifies that
2372    * predicate of a reified axiom
2373    *
2374    * @return The IRI, by default this is owl:annotatedProperty
2375    */
 
2376  620 toggle protected static OWLRDFVocabulary getPropertyTriplePredicate() {
2377  620 return OWL_ANNOTATED_PROPERTY;
2378    }
2379   
2380    /**
2381    * Gets the IRI of the predicate of the triple that specifies the source
2382    * of a reified axiom
2383    *
2384    * @return The IRI, by default this is owl:annotatedSource
2385    */
 
2386  620 toggle protected static OWLRDFVocabulary getSourceTriplePredicate() {
2387  620 return OWL_ANNOTATED_SOURCE;
2388    }
2389   
 
2390  620 toggle @Override
2391    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2392  620 IRI annotatedSource = getObjectOfSourceTriple(subject);
2393  620 IRI annotatedProperty = getObjectOfPropertyTriple(subject);
2394  620 IRI annotatedTarget = getObjectOfTargetTriple(subject);
2395  620 OWLLiteral annotatedTargetLiteral = null;
2396  620 if (annotatedTarget == null) {
2397  42 annotatedTargetLiteral = getTargetLiteral(subject);
2398    }
2399    // check that other conditions are not invalid
2400  620 if (annotatedSource != null && annotatedProperty != null) {
2401  620 consumeTriple(subject, predicate, object);
2402  620 Set<OWLAnnotation> annotations = consumer.translateAnnotations(subject);
2403  620 consumer.addPendingAnnotations(annotations);
2404  620 if (annotatedTarget != null) {
2405  578 consumer.handlerAccessor.handle(annotatedSource, annotatedProperty, annotatedTarget);
2406  42 } else if (annotatedTargetLiteral != null) {
2407  42 consumer.handlerAccessor.handle(annotatedSource, annotatedProperty, annotatedTargetLiteral);
2408    }
2409  620 if (!annotations.isEmpty()) {
2410  620 OWLAxiom ax = consumer.getLastAddedAxiom();
2411  620 consumer.removeAxiom(ax.getAxiomWithoutAnnotations());
2412    }
2413    }
2414    }
2415   
 
2416  0 toggle @SuppressWarnings("unused")
2417    protected OWLAxiom handleAxiomTriples(IRI subjectTriple, IRI predicateTriple, IRI objectTriple,
2418    Set<OWLAnnotation> annotations) {
2419    // Reconstitute the original triple from the reification triples
2420  0 return consumer.getLastAddedAxiom();
2421    }
2422   
 
2423  0 toggle protected OWLAxiom handleAxiomTriples(@Nonnull IRI subjectTripleObject, @Nonnull IRI predicateTripleObject,
2424    @Nonnull OWLLiteral con, @SuppressWarnings("unused") Set<OWLAnnotation> annotations) {
2425  0 consumer.handlerAccessor.handle(subjectTripleObject, predicateTripleObject, con);
2426  0 return consumer.getLastAddedAxiom();
2427    }
2428   
 
2429  42 toggle @Nonnull
2430    private OWLLiteral getTargetLiteral(IRI subject) {
2431  42 OWLLiteral con = consumer.getLiteralObject(subject, getTargetTriplePredicate(), true);
2432  42 if (con == null) {
2433  0 con = consumer.getLiteralObject(subject, DeprecatedVocabulary.RDF_OBJECT, true);
2434    }
2435  42 return verifyNotNull(con);
2436    }
2437   
2438    /**
2439    * Gets the object of the target triple that has the specified main node
2440    *
2441    * @param mainNode
2442    * The main node
2443    * @return The object of the triple that has the specified mainNode as
2444    * its subject and the IRI returned by the
2445    * {@code TypeAxiomHandler#getSourceTriplePredicate()} method.
2446    * For backwards compatibility, a search will also be performed
2447    * for triples whos subject is the specified mainNode and
2448    * predicate rdf:object
2449    */
 
2450  620 toggle @Nullable
2451    private IRI getObjectOfTargetTriple(IRI mainNode) {
2452  620 IRI objectTripleObject = consumer.getResourceObject(mainNode, getTargetTriplePredicate(), true);
2453  620 if (objectTripleObject == null) {
2454  42 objectTripleObject = consumer.getResourceObject(mainNode, DeprecatedVocabulary.RDF_OBJECT, true);
2455    }
2456  620 if (objectTripleObject == null) {
2457  42 objectTripleObject = consumer.getResourceObject(mainNode, DeprecatedVocabulary.OWL_PROPERTY_CHAIN,
2458    true);
2459    }
2460  620 return objectTripleObject;
2461    }
2462   
 
2463  620 toggle @Nullable
2464    private IRI getObjectOfPropertyTriple(IRI subject) {
2465  620 IRI predicateTripleObject = consumer.getResourceObject(subject, getPropertyTriplePredicate(), true);
2466  620 if (predicateTripleObject == null) {
2467  0 predicateTripleObject = consumer.getResourceObject(subject, DeprecatedVocabulary.RDF_PREDICATE, true);
2468    }
2469  620 return predicateTripleObject;
2470    }
2471   
2472    /**
2473    * Gets the source IRI for an annotated or reified axiom
2474    *
2475    * @param mainNode
2476    * The main node of the triple
2477    * @return The source object
2478    * @throws OWLRDFXMLParserMalformedNodeException
2479    * malformed node
2480    */
 
2481  620 toggle @Nullable
2482    private IRI getObjectOfSourceTriple(IRI mainNode) {
2483  620 IRI subjectTripleObject = consumer.getResourceObject(mainNode, getSourceTriplePredicate(), true);
2484  620 if (subjectTripleObject == null) {
2485  0 subjectTripleObject = consumer.getResourceObject(mainNode, DeprecatedVocabulary.RDF_SUBJECT, true);
2486    }
2487  620 return subjectTripleObject;
2488    }
2489    }
2490   
 
2491    static class TypeClassHandler extends AbstractBuiltInTypeHandler {
2492   
 
2493  3105 toggle TypeClassHandler(@Nonnull OWLRDFConsumer consumer) {
2494  3105 super(consumer, OWL_CLASS.getIRI());
2495    }
2496   
 
2497  16197 toggle @Override
2498    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2499  16197 if (!isAnonymous(subject)) {
2500  14960 Set<OWLAnnotation> annos = consumer.getPendingAnnotations();
2501  14960 OWLClass owlClass = df.getOWLClass(subject);
2502  14960 addAxiom(df.getOWLDeclarationAxiom(owlClass, annos));
2503    }
2504  16197 consumer.addClassExpression(subject, true);
2505    }
2506    }
2507   
 
2508    static class TypeDataPropertyHandler extends AbstractBuiltInTypeHandler {
2509   
 
2510  3105 toggle TypeDataPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2511  3105 super(consumer, OWL_DATA_PROPERTY.getIRI());
2512    }
2513   
 
2514  964 toggle @Override
2515    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2516  964 if (!isAnonymous(subject)) {
2517  964 Set<OWLAnnotation> annos = consumer.getPendingAnnotations();
2518  964 OWLDataProperty owlDataProperty = df.getOWLDataProperty(subject);
2519  964 addAxiom(df.getOWLDeclarationAxiom(owlDataProperty, annos));
2520    }
2521  964 consumer.addDataProperty(subject, true);
2522    }
2523    }
2524   
 
2525    static class TypeDataRangeHandler extends AbstractBuiltInTypeHandler {
2526   
 
2527  3105 toggle TypeDataRangeHandler(@Nonnull OWLRDFConsumer consumer) {
2528  3105 super(consumer, OWL_DATA_RANGE.getIRI());
2529    }
2530   
 
2531  0 toggle @Override
2532    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2533  0 if (!isAnonymous(subject)) {
2534  0 consumeTriple(subject, predicate, object);
2535    }
2536    }
2537    }
2538   
 
2539    static class TypeDatatypeHandler extends AbstractBuiltInTypeHandler {
2540   
 
2541  3105 toggle TypeDatatypeHandler(@Nonnull OWLRDFConsumer consumer) {
2542  3105 super(consumer, RDFS_DATATYPE.getIRI());
2543    }
2544   
 
2545  612 toggle @Override
2546    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2547  612 if (!consumer.isAnonymousNode(subject)) {
2548  245 OWLDatatype dt = df.getOWLDatatype(subject);
2549  245 Set<OWLAnnotation> annos = consumer.getPendingAnnotations();
2550  245 addAxiom(df.getOWLDeclarationAxiom(dt, annos));
2551    }
2552  612 consumer.addDataRange(subject, true);
2553    }
2554    }
2555   
 
2556    static class TypeDeprecatedClassHandler extends AbstractBuiltInTypeHandler {
2557   
 
2558  3105 toggle TypeDeprecatedClassHandler(@Nonnull OWLRDFConsumer consumer) {
2559  3105 super(consumer, OWL_DEPRECATED_CLASS.getIRI());
2560    }
2561   
 
2562  1 toggle @Override
2563    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2564  1 consumer.addClassExpression(subject, false);
2565  1 consumeTriple(subject, predicate, object);
2566  1 addAxiom(df.getDeprecatedOWLAnnotationAssertionAxiom(subject));
2567    }
2568    }
2569   
 
2570    static class TypeDeprecatedPropertyHandler extends AbstractBuiltInTypeHandler {
2571   
 
2572  3105 toggle TypeDeprecatedPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2573  3105 super(consumer, OWL_DEPRECATED_PROPERTY.getIRI());
2574    }
2575   
 
2576  1 toggle @Override
2577    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2578  1 consumeTriple(subject, predicate, object);
2579  1 addAxiom(df.getDeprecatedOWLAnnotationAssertionAxiom(subject));
2580    }
2581    }
2582   
 
2583    static class TypeFunctionalPropertyHandler extends AbstractBuiltInTypeHandler {
2584   
 
2585  3105 toggle TypeFunctionalPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2586  3105 super(consumer, OWL_FUNCTIONAL_PROPERTY.getIRI());
2587    }
2588   
 
2589  494 toggle @Override
2590    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2591  494 return false;
2592    }
2593   
 
2594  270 toggle @Override
2595    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2596  270 if (consumer.isObjectProperty(subject)) {
2597  177 addAxiom(df.getOWLFunctionalObjectPropertyAxiom(translateObjectProperty(subject),
2598    getPendingAnnotations()));
2599  177 consumeTriple(subject, predicate, object);
2600    }
2601  270 if (consumer.isDataProperty(subject)) {
2602  92 addAxiom(df.getOWLFunctionalDataPropertyAxiom(translateDataProperty(subject), getPendingAnnotations()));
2603  92 consumeTriple(subject, predicate, object);
2604    }
2605    }
2606    }
2607   
 
2608    static class TypeInverseFunctionalPropertyHandler extends AbstractBuiltInTypeHandler {
2609   
 
2610  3105 toggle TypeInverseFunctionalPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2611  3105 super(consumer, OWL_INVERSE_FUNCTIONAL_PROPERTY.getIRI());
2612    }
2613   
 
2614  71 toggle @Override
2615    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2616  71 consumer.handlerAccessor.handle(subject, predicate, OWL_OBJECT_PROPERTY.getIRI());
2617  71 return !isAnonymous(subject);
2618    }
2619   
 
2620  79 toggle @Override
2621    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2622  79 if (consumer.isObjectProperty(subject)) {
2623  79 OWLObjectPropertyExpression property = translateObjectProperty(subject);
2624  79 addAxiom(df.getOWLInverseFunctionalObjectPropertyAxiom(property, getPendingAnnotations()));
2625  79 consumeTriple(subject, predicate, object);
2626    }
2627    }
2628    }
2629   
 
2630    static class TypeIrreflexivePropertyHandler extends AbstractBuiltInTypeHandler {
2631   
 
2632  3105 toggle TypeIrreflexivePropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2633  3105 super(consumer, OWL_IRREFLEXIVE_PROPERTY.getIRI());
2634    }
2635   
 
2636  65 toggle @Override
2637    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2638  65 consumer.addObjectProperty(subject, false);
2639  65 return !isAnonymous(subject);
2640    }
2641   
 
2642  73 toggle @Override
2643    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2644  73 if (consumer.isObjectProperty(subject)) {
2645  73 addAxiom(df.getOWLIrreflexiveObjectPropertyAxiom(translateObjectProperty(subject),
2646    getPendingAnnotations()));
2647  73 consumeTriple(subject, predicate, object);
2648    }
2649    }
2650    }
2651   
 
2652    static class TypeListHandler extends AbstractBuiltInTypeHandler {
2653   
 
2654  3105 toggle TypeListHandler(@Nonnull OWLRDFConsumer consumer) {
2655  3105 super(consumer, RDF_LIST.getIRI());
2656    }
2657   
 
2658  23098 toggle @Override
2659    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2660  23098 consumeTriple(subject, predicate, object);
2661    }
2662    }
2663   
 
2664    static class TypeNamedIndividualHandler extends AbstractBuiltInTypeHandler {
2665   
 
2666  3105 toggle TypeNamedIndividualHandler(@Nonnull OWLRDFConsumer consumer) {
2667  3105 super(consumer, OWL_NAMED_INDIVIDUAL.getIRI());
2668    }
2669   
 
2670  8880 toggle @Override
2671    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2672  8880 if (!isAnonymous(subject)) {
2673  8879 Set<OWLAnnotation> annos = consumer.getPendingAnnotations();
2674  8879 OWLNamedIndividual individual = df.getOWLNamedIndividual(subject);
2675  8879 addAxiom(df.getOWLDeclarationAxiom(individual, annos));
2676    }
2677  8880 consumer.addOWLNamedIndividual(subject, true);
2678    }
2679    }
2680   
 
2681    static class TypeNegativeDataPropertyAssertionHandler extends AbstractBuiltInTypeHandler {
2682   
 
2683  3105 toggle TypeNegativeDataPropertyAssertionHandler(@Nonnull OWLRDFConsumer consumer) {
2684  3105 super(consumer, DeprecatedVocabulary.OWL_NEGATIVE_DATA_PROPERTY_ASSERTION);
2685    }
2686   
 
2687  0 toggle @Override
2688    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2689  0 return false;
2690    }
2691   
 
2692  0 toggle @Override
2693    public void handleTriple(@Nonnull IRI subject, @Nonnull IRI predicate, @Nonnull IRI object) {
2694  0 IRI source = source(subject);
2695  0 IRI property = property(subject);
2696  0 OWLLiteral target = target(subject);
2697  0 OWLIndividual sourceInd = consumer.getOWLIndividual(source);
2698  0 OWLDataPropertyExpression prop = consumer.translateDataPropertyExpression(property);
2699  0 consumeTriple(subject, predicate, object);
2700  0 consumer.translateAnnotations(subject);
2701  0 Set<OWLAnnotation> annos = consumer.getPendingAnnotations();
2702  0 addAxiom(df.getOWLNegativeDataPropertyAssertionAxiom(prop, sourceInd, target, annos));
2703    }
2704   
 
2705  0 toggle @Nonnull
2706    OWLLiteral target(IRI subject) {
2707  0 OWLLiteral target = consumer.getLiteralObject(subject, OWL_TARGET_VALUE.getIRI(), true);
2708  0 if (target == null) {
2709  0 target = consumer.getLiteralObject(subject, DeprecatedVocabulary.OWL_OBJECT, true);
2710    }
2711  0 if (target == null) {
2712  0 target = consumer.getLiteralObject(subject, DeprecatedVocabulary.RDF_OBJECT, true);
2713    }
2714  0 return verifyNotNull(target);
2715    }
2716   
 
2717  0 toggle @Nonnull
2718    IRI property(IRI subject) {
2719  0 IRI property = consumer.getResourceObject(subject, OWL_ASSERTION_PROPERTY.getIRI(), true);
2720  0 if (property == null) {
2721  0 property = consumer.getResourceObject(subject, DeprecatedVocabulary.OWL_PREDICATE, true);
2722    }
2723  0 if (property == null) {
2724  0 property = consumer.getResourceObject(subject, DeprecatedVocabulary.RDF_PREDICATE, true);
2725    }
2726  0 return verifyNotNull(property);
2727    }
2728   
 
2729  0 toggle @Nonnull
2730    IRI source(IRI subject) {
2731  0 IRI source = consumer.getResourceObject(subject, OWL_SOURCE_INDIVIDUAL.getIRI(), true);
2732  0 if (source == null) {
2733  0 source = consumer.getResourceObject(subject, DeprecatedVocabulary.OWL_SUBJECT, true);
2734    }
2735  0 if (source == null) {
2736  0 source = consumer.getResourceObject(subject, DeprecatedVocabulary.RDF_SUBJECT, true);
2737    }
2738  0 return verifyNotNull(source);
2739    }
2740    }
2741   
 
2742    static class TypeNegativePropertyAssertionHandler extends AbstractBuiltInTypeHandler {
2743   
 
2744  3105 toggle TypeNegativePropertyAssertionHandler(@Nonnull OWLRDFConsumer consumer) {
2745  3105 super(consumer, OWL_NEGATIVE_PROPERTY_ASSERTION.getIRI());
2746    }
2747   
 
2748  0 toggle @Override
2749    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2750  0 return false;
2751    }
2752   
 
2753  1114 toggle @Override
2754    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2755  1114 IRI source = source(subject);
2756  1114 IRI property = property(subject);
2757  1114 Object target = target(subject);
2758  1114 Set<OWLAnnotation> annos = consumer.translateAnnotations(subject);
2759  1114 if (target instanceof OWLLiteral && (!isStrict() || consumer.isDataProperty(property))) {
2760  73 translateNegativeDataPropertyAssertion(subject, predicate, object, source, property,
2761    (OWLLiteral) target, annos);
2762  1041 } else if (target instanceof IRI && (!isStrict() || consumer.isObjectProperty(property))) {
2763  1041 translateNegativeObjectPropertyAssertion(subject, predicate, object, source, property, (IRI) target,
2764    annos);
2765    }
2766    // TODO LOG ERROR
2767    }
2768   
 
2769  1114 toggle @Nonnull
2770    Object target(IRI subject) {
2771  1114 Object target = consumer.getResourceObject(subject, OWL_TARGET_INDIVIDUAL.getIRI(), true);
2772  1114 if (target == null) {
2773  73 target = consumer.getLiteralObject(subject, OWL_TARGET_VALUE.getIRI(), true);
2774    }
2775  1114 if (target == null) {
2776  0 target = consumer.getResourceObject(subject, DeprecatedVocabulary.RDF_OBJECT, true);
2777    }
2778  1114 if (target == null) {
2779  0 target = consumer.getLiteralObject(subject, DeprecatedVocabulary.RDF_OBJECT, true);
2780    }
2781  1114 return verifyNotNull(target);
2782    }
2783   
 
2784  1114 toggle @Nonnull
2785    IRI property(IRI subject) {
2786  1114 IRI property = consumer.getResourceObject(subject, OWL_ASSERTION_PROPERTY.getIRI(), true);
2787  1114 if (property == null) {
2788  0 property = consumer.getResourceObject(subject, DeprecatedVocabulary.RDF_PREDICATE, true);
2789    }
2790  1114 return verifyNotNull(property);
2791    }
2792   
 
2793  1114 toggle @Nonnull
2794    IRI source(IRI subject) {
2795  1114 IRI source = consumer.getResourceObject(subject, OWL_SOURCE_INDIVIDUAL.getIRI(), true);
2796  1114 if (source == null) {
2797  0 source = consumer.getResourceObject(subject, DeprecatedVocabulary.RDF_SUBJECT, true);
2798    }
2799  1114 return verifyNotNull(source);
2800    }
2801   
 
2802  1041 toggle private void translateNegativeObjectPropertyAssertion(@Nonnull IRI subject, @Nonnull IRI predicate,
2803    @Nonnull IRI object, @Nonnull IRI source, @Nonnull IRI property, @Nonnull IRI target,
2804    @Nonnull Set<OWLAnnotation> annos) {
2805  1041 OWLIndividual sourceInd = consumer.getOWLIndividual(source);
2806  1041 OWLObjectPropertyExpression prop = consumer.translateObjectPropertyExpression(property);
2807  1041 OWLIndividual targetInd = consumer.getOWLIndividual(target);
2808  1041 consumeTriple(subject, predicate, object);
2809  1041 addAxiom(df.getOWLNegativeObjectPropertyAssertionAxiom(prop, sourceInd, targetInd, annos));
2810    }
2811   
 
2812  73 toggle private void translateNegativeDataPropertyAssertion(@Nonnull IRI subject, @Nonnull IRI predicate,
2813    @Nonnull IRI object, @Nonnull IRI source, @Nonnull IRI property, @Nonnull OWLLiteral target,
2814    @Nonnull Set<OWLAnnotation> annos) {
2815  73 OWLIndividual sourceInd = consumer.getOWLIndividual(source);
2816  73 OWLDataPropertyExpression prop = consumer.translateDataPropertyExpression(property);
2817  73 consumeTriple(subject, predicate, object);
2818  73 addAxiom(df.getOWLNegativeDataPropertyAssertionAxiom(prop, sourceInd, target, annos));
2819    }
2820    }
2821   
 
2822    static class TypeObjectPropertyHandler extends AbstractBuiltInTypeHandler {
2823   
 
2824  3105 toggle TypeObjectPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2825  3105 super(consumer, OWL_OBJECT_PROPERTY.getIRI());
2826    }
2827   
 
2828  3035 toggle @Override
2829    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2830  3035 if (!isAnonymous(subject)) {
2831  2991 OWLObjectProperty owlObjectProperty = df.getOWLObjectProperty(subject);
2832  2991 Set<OWLAnnotation> annos = getPendingAnnotations();
2833  2991 addAxiom(df.getOWLDeclarationAxiom(owlObjectProperty, annos));
2834    }
2835  3035 consumer.addObjectProperty(subject, true);
2836    }
2837    }
2838   
 
2839    static class TypeOntologyHandler extends AbstractBuiltInTypeHandler {
2840   
 
2841  3105 toggle TypeOntologyHandler(@Nonnull OWLRDFConsumer consumer) {
2842  3105 super(consumer, OWL_ONTOLOGY.getIRI());
2843    }
2844   
 
2845  1906 toggle @Override
2846    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2847  1906 consumeTriple(subject, predicate, object);
2848  1906 if (!isAnonymous(subject) && consumer.getOntologies().isEmpty()) {
2849    // Set IRI if it is not null before this point, and make sure to
2850    // preserve the version IRI if it also existed before this point
2851  1402 if (!consumer.getOntology().getOntologyID().getOntologyIRI().isPresent()) {
2852  1402 OWLOntologyID id = new OWLOntologyID(Optional.of(subject), consumer.getOntology().getOntologyID()
2853    .getVersionIRI());
2854  1402 consumer.applyChange(new SetOntologyID(consumer.getOntology(), id));
2855    }
2856    }
2857  1905 consumer.addOntology(subject);
2858    }
2859    }
2860   
 
2861    static class TypeOntologyPropertyHandler extends AbstractBuiltInTypeHandler {
2862   
 
2863  3105 toggle TypeOntologyPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2864  3105 super(consumer, DeprecatedVocabulary.OWL_ONTOLOGY_PROPERTY);
2865    }
2866   
 
2867  1 toggle @Override
2868    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2869  1 consumeTriple(subject, predicate, object);
2870    // Add a type triple for an annotation property (Table 6 in Mapping
2871    // to RDF Graph Spec)
2872  1 consumer.handlerAccessor.handle(subject, predicate, OWL_ANNOTATION_PROPERTY.getIRI());
2873    }
2874    }
2875   
 
2876    static class TypePropertyHandler extends AbstractBuiltInTypeHandler {
2877   
 
2878  3105 toggle TypePropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2879  3105 super(consumer, RDF_PROPERTY.getIRI());
2880    }
2881   
 
2882  1107 toggle @Override
2883    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2884    // We need to consume this triple
2885  1107 consumeTriple(subject, predicate, object);
2886  1107 LOGGER.info("Usage of rdf vocabulary: {} -> {} -> {}", subject, predicate, object);
2887    }
2888    }
2889   
 
2890    static class TypeRDFSClassHandler extends AbstractBuiltInTypeHandler {
2891   
 
2892  3105 toggle TypeRDFSClassHandler(@Nonnull OWLRDFConsumer consumer) {
2893  3105 super(consumer, RDFS_CLASS.getIRI());
2894    }
2895   
 
2896  352 toggle @Override
2897    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2898    // TODO: Change to rdfs:Class? (See table 5 in the spec)
2899  352 consumer.addClassExpression(subject, false);
2900  352 consumeTriple(subject, predicate, object);
2901  352 if (!isStrict()) {
2902  352 consumer.handlerAccessor.handle(subject, predicate, OWL_CLASS.getIRI());
2903    }
2904    }
2905    }
2906   
 
2907    static class TypeReflexivePropertyHandler extends AbstractBuiltInTypeHandler {
2908   
 
2909  3105 toggle TypeReflexivePropertyHandler(@Nonnull OWLRDFConsumer consumer) {
2910  3105 super(consumer, OWL_REFLEXIVE_PROPERTY.getIRI());
2911    }
2912   
 
2913  64 toggle @Override
2914    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
2915  64 consumer.addObjectProperty(subject, false);
2916  64 return !isAnonymous(subject);
2917    }
2918   
 
2919  72 toggle @Override
2920    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2921  72 if (consumer.isObjectProperty(subject)) {
2922  72 addAxiom(df.getOWLReflexiveObjectPropertyAxiom(translateObjectProperty(subject),
2923    getPendingAnnotations()));
2924  72 consumeTriple(subject, predicate, object);
2925    }
2926    }
2927    }
2928   
 
2929    static class TypeRestrictionHandler extends AbstractBuiltInTypeHandler {
2930   
 
2931  3105 toggle TypeRestrictionHandler(@Nonnull OWLRDFConsumer consumer) {
2932  3105 super(consumer, OWL_RESTRICTION.getIRI());
2933    }
2934   
 
2935  2416 toggle @Override
2936    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2937  2416 consumeTriple(subject, predicate, object);
2938  2416 consumer.addOWLRestriction(subject, true);
2939  2416 consumer.addClassExpression(subject, false);
2940    }
2941    }
2942   
 
2943    static class TypeSWRLAtomListHandler extends AbstractBuiltInTypeHandler {
2944   
 
2945  3101 toggle TypeSWRLAtomListHandler(@Nonnull OWLRDFConsumer consumer) {
2946  3101 super(consumer, SWRLVocabulary.ATOM_LIST.getIRI());
2947    }
2948   
 
2949  210 toggle @Override
2950    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2951  210 consumeTriple(subject, predicate, object);
2952    }
2953    }
2954   
 
2955    static class TypeSWRLBuiltInAtomHandler extends AbstractBuiltInTypeHandler {
2956   
 
2957  3101 toggle TypeSWRLBuiltInAtomHandler(@Nonnull OWLRDFConsumer consumer) {
2958  3101 super(consumer, SWRLVocabulary.BUILT_IN_ATOM.getIRI());
2959    }
2960   
 
2961  17 toggle @Override
2962    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2963  17 consumer.addSWRLBuiltInAtom(subject);
2964  17 consumeTriple(subject, predicate, object);
2965    }
2966    }
2967   
 
2968    static class TypeSWRLBuiltInHandler extends AbstractBuiltInTypeHandler {
2969   
 
2970  3101 toggle TypeSWRLBuiltInHandler(@Nonnull OWLRDFConsumer consumer) {
2971  3101 super(consumer, SWRLVocabulary.BUILT_IN_CLASS.getIRI());
2972    }
2973   
 
2974  10 toggle @Override
2975    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2976    // Just consume - I don't care about this
2977  10 consumeTriple(subject, predicate, object);
2978    }
2979    }
2980   
 
2981    static class TypeSWRLClassAtomHandler extends AbstractBuiltInTypeHandler {
2982   
 
2983  3101 toggle TypeSWRLClassAtomHandler(@Nonnull OWLRDFConsumer consumer) {
2984  3101 super(consumer, SWRLVocabulary.CLASS_ATOM.getIRI());
2985    }
2986   
 
2987  94 toggle @Override
2988    public void handleTriple(IRI subject, IRI predicate, IRI object) {
2989  94 consumer.addSWRLClassAtom(subject);
2990  94 consumeTriple(subject, predicate, object);
2991    }
2992    }
2993   
 
2994    static class TypeSWRLDataRangeAtomHandler extends AbstractBuiltInTypeHandler {
2995   
 
2996  3101 toggle TypeSWRLDataRangeAtomHandler(@Nonnull OWLRDFConsumer consumer) {
2997  3101 super(consumer, SWRLVocabulary.DATA_RANGE_ATOM.getIRI());
2998    }
2999   
 
3000  2 toggle @Override
3001    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3002  2 consumer.addSWRLDataRangeAtom(subject);
3003  2 consumeTriple(subject, predicate, object);
3004    }
3005    }
3006   
 
3007    static class TypeSWRLDataValuedPropertyAtomHandler extends AbstractBuiltInTypeHandler {
3008   
 
3009  3101 toggle TypeSWRLDataValuedPropertyAtomHandler(@Nonnull OWLRDFConsumer consumer) {
3010  3101 super(consumer, SWRLVocabulary.DATAVALUED_PROPERTY_ATOM.getIRI());
3011    }
3012   
 
3013  34 toggle @Override
3014    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3015  34 consumeTriple(subject, predicate, object);
3016  34 consumer.addSWRLDataPropertyAtom(subject);
3017    }
3018    }
3019   
 
3020    static class TypeSWRLDifferentIndividualsAtomHandler extends AbstractBuiltInTypeHandler {
3021   
 
3022  3101 toggle TypeSWRLDifferentIndividualsAtomHandler(@Nonnull OWLRDFConsumer consumer) {
3023  3101 super(consumer, SWRLVocabulary.DIFFERENT_INDIVIDUALS_ATOM.getIRI());
3024    }
3025   
 
3026  32 toggle @Override
3027    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3028  32 consumer.addSWRLDifferentFromAtom(subject);
3029  32 consumeTriple(subject, predicate, object);
3030    }
3031    }
3032   
 
3033    static class TypeSWRLImpHandler extends AbstractBuiltInTypeHandler {
3034   
 
3035  3101 toggle TypeSWRLImpHandler(@Nonnull OWLRDFConsumer consumer) {
3036  3101 super(consumer, SWRLVocabulary.IMP.getIRI());
3037    }
3038   
 
3039  26 toggle @Override
3040    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3041  26 IRI remapIRI = consumer.remapIRI(subject);
3042  26 consumeTriple(remapIRI, predicate, object);
3043  26 consumer.addSWRLRule(remapIRI);
3044    }
3045    }
3046   
 
3047    static class TypeSWRLIndividualPropertyAtomHandler extends AbstractBuiltInTypeHandler {
3048   
 
3049  3101 toggle TypeSWRLIndividualPropertyAtomHandler(@Nonnull OWLRDFConsumer consumer) {
3050  3101 super(consumer, SWRLVocabulary.INDIVIDUAL_PROPERTY_ATOM.getIRI());
3051    }
3052   
 
3053  23 toggle @Override
3054    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3055  23 consumeTriple(subject, predicate, object);
3056  23 consumer.addSWRLIndividualPropertyAtom(subject);
3057    }
3058    }
3059   
 
3060    static class TypeSWRLSameIndividualAtomHandler extends AbstractBuiltInTypeHandler {
3061   
 
3062  3101 toggle TypeSWRLSameIndividualAtomHandler(@Nonnull OWLRDFConsumer consumer) {
3063  3101 super(consumer, SWRLVocabulary.SAME_INDIVIDUAL_ATOM.getIRI());
3064    }
3065   
 
3066  32 toggle @Override
3067    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3068  32 consumer.addSWRLSameAsAtom(subject);
3069  32 consumeTriple(subject, predicate, object);
3070    }
3071    }
3072   
 
3073    static class TypeSWRLVariableHandler extends AbstractBuiltInTypeHandler {
3074   
 
3075  3101 toggle TypeSWRLVariableHandler(@Nonnull OWLRDFConsumer consumer) {
3076  3101 super(consumer, SWRLVocabulary.VARIABLE.getIRI());
3077    }
3078   
 
3079  90 toggle @Override
3080    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3081  90 consumer.addSWRLVariable(subject);
3082  90 consumeTriple(subject, predicate, object);
3083    }
3084    }
3085   
 
3086    static class TypeSelfRestrictionHandler extends AbstractBuiltInTypeHandler {
3087   
 
3088  3105 toggle TypeSelfRestrictionHandler(@Nonnull OWLRDFConsumer consumer) {
3089  3105 super(consumer, DeprecatedVocabulary.OWL_SELF_RESTRICTION);
3090    }
3091   
 
3092  0 toggle @Override
3093    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3094  0 consumeTriple(subject, predicate, object);
3095  0 consumer.addOWLRestriction(subject, false);
3096    // Patch to new OWL syntax
3097  0 consumer.addTriple(subject, OWL_HAS_SELF.getIRI(), df.getOWLLiteral(true));
3098    }
3099    }
3100   
 
3101    static class TypeSymmetricPropertyHandler extends AbstractBuiltInTypeHandler {
3102   
 
3103  3105 toggle TypeSymmetricPropertyHandler(@Nonnull OWLRDFConsumer consumer) {
3104  3105 super(consumer, OWL_SYMMETRIC_PROPERTY.getIRI());
3105    }
3106   
 
3107  68 toggle @Override
3108    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
3109  68 if (!isAnonymous(subject)) {
3110  60 consumer.handlerAccessor.handle(subject, predicate, OWL_OBJECT_PROPERTY.getIRI());
3111    }
3112  68 consumer.addObjectProperty(subject, false);
3113  68 return !isAnonymous(subject);
3114    }
3115   
 
3116  76 toggle @Override
3117    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3118  76 if (consumer.isObjectProperty(subject)) {
3119  76 addAxiom(df.getOWLSymmetricObjectPropertyAxiom(translateObjectProperty(subject),
3120    getPendingAnnotations()));
3121  76 consumeTriple(subject, predicate, object);
3122    }
3123    }
3124    }
3125   
 
3126    static class TypeTransitivePropertyHandler extends AbstractBuiltInTypeHandler {
3127   
 
3128  3105 toggle TypeTransitivePropertyHandler(@Nonnull OWLRDFConsumer consumer) {
3129  3105 super(consumer, OWL_TRANSITIVE_PROPERTY.getIRI());
3130    }
3131   
 
3132  108 toggle @Override
3133    public boolean canHandleStreaming(IRI subject, IRI predicate, IRI object) {
3134  108 consumer.handlerAccessor.handle(subject, predicate, OWL_OBJECT_PROPERTY.getIRI());
3135  108 return !isAnonymous(subject);
3136    }
3137   
 
3138  116 toggle @Override
3139    public void handleTriple(IRI subject, IRI predicate, IRI object) {
3140  116 addAxiom(df.getOWLTransitiveObjectPropertyAxiom(translateObjectProperty(subject), getPendingAnnotations()));
3141  116 consumeTriple(subject, predicate, object);
3142    }
3143    }
3144    }